• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Simple function problems. I think...

Status
Not open for further replies.
Level 12
Joined
Jun 15, 2016
Messages
472
I tried creating a skeleton spawning system, and after a lot of simplification, I got to a test map with the following code:

JASS:
function First_Encounter_Birth takes unit u returns nothing
    local rect temp_loc = GetUnitLoc(u)
    call SetUnitAnimation (u,"birth") // type mismatch in assignment
    call DestroyEffect(AddSpecialEffectLoc("Abilities\Spells\Undead\RaiseSkeletonWarrior\RaiseSkeleton.mdl",temp_loc)) // excpected a valid arguement list
endfunction

function First_Encounter_Set takes nothing returns nothing
    call CreateUnitAtLoc(1,"uske",SpawnPoint,315)
    local unit temp = GetLastCreatedUnit()
    call First_Encounter_Birth(temp)
endfunction   

function InitTrig_JASS_Test takes nothing returns nothing
    local trigger JASS_Test = CreateTrigger()
        call TriggerRegisterEnterRegionSimple(JASS_Test,footswitch)
        call TriggerAddAction (JASS_Test,function )
    set JASS_Test = null
endfunction

It has 2 errors that I typed in comments, and I don't know why I got them (What wrong arguments/argument order).

What's really bothering me though are 2 more errors in the map config section, Which I did not touch (except deleting the map initialization triggers maybe?) which are also commented below:
JASS:
    call InitCustomPlayerSlots(  ) // expected a fuction name
    call SetPlayerSlotAvailable( Player(0), MAP_CONTROL_USER )
    call InitGenericPlayerSlots(  ) // expected a code statement

any ideas?
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
"// type mismatch in assignment"
"local rect temp_loc = GetUnitLoc(u)"
Since when are locations called "rect"s?

This will also fix the other problem (syntax errors are ussually connected).

The other one is slightly more interesting... and odd.
The functions like "InitCustomPlayerSlots()" are auto-generated for every map on save to initialize the game data via JASS.
However, this one seems to be called before definition or is missing entirely.
If the problem still exists after fixing the other 2 (1 actually), then open the map with an mpq editor and upload the content of the war3map.j.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
Level 24
Joined
Aug 1, 2013
Messages
4,658
On a side note, CreateUnit natives do not work with "bj_lastCreatedUnit" (GetLastCreatedUnit())
This is a Blizzard.j functionality which is completely unnecessary in JASS as you can use the returned type of the CreateUnit natives.
So:
local unit u = CreateUnitAtLoc(1,"uske",SpawnPoint,315)

Do not forget to null the local variables at the end of the function:
set u = null
Same for rect, loc, etc.
(To make it simple, all types except integer, string, real, boolean and code... if you want to find out which types have to be nulled, then look in the Common.j and look for all types that extend "agent".)
 
Level 12
Joined
Jun 15, 2016
Messages
472
Thanks for the help so far, now the only problem left is the one with the model (expected a valid arguement list). I assume it means my arguments are jumbled somehow, but that's the argument order described in jasscraft and switching their places did not work.

Locals should go first.

Is this a matter of normal coding order or does it actually cause problems?

Or don't use locations at all and just use coordinates (x & y).

Why not use locations?
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
You should definately download JNGP 2.0.
The error messages are so wrong here.

In strings (in every decent programming language) a "\" character is an escape character.
An escape character is used to write down unprintable characters like a tab, a newline/carriage return, string marks (ussually quotation marks) etc, etc, etc.
However, that means that writing a single "\" is not going to work.
To write an actual backslash in a string, you have to write it twice to make the compiler know that you want to place a backslash.

So your model string must be: "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl"

About the locals on top, this is something of JASS, I dont know if any other programming/scripting language has this, but the languages that I use, are not limited to this.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
Is this a matter of normal coding order or does it actually cause problems?
It is a technical limitation. Same as C has. Only newer standards of C removed that restriction.

Why not use locations?
Locations can be passed around faster but take longer to set up. If one only needs to reference a point once or twice it is faster to use X/Y coordinate reals than a location. Locations are complex objects that need a function call to create, and another to remove as well as local declared local locations variables require nulling before function return, all of which is overhead.
 
Level 12
Joined
Jun 15, 2016
Messages
472
I'm reviving this thread for a question regarding the same piece of code. This script:

JASS:
function Encounter_Animation takes unit u returns nothing
    local location temp_loc = GetUnitLoc(u)
   
    //call BJDebugMsg("eyecandy function fires")
    call SetUnitAnimation (u,"birth")
    call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl",temp_loc))
    call RemoveLocation(temp_loc)
    set temp_loc = null
endfunction

function Encounter_Set takes nothing returns nothing
    local location SpawnPoint = Location(-144,-176)
    local unit temp = CreateUnitAtLoc(Player(1),'uske',SpawnPoint,315)

    //call BJDebugMsg("Action function fires")
    call Encounter_Animation(temp)
    call RemoveLocation(SpawnPoint)
    set SpawnPoint = null
    set temp = null
endfunction

function InitTrig_JASS_Test takes nothing returns nothing
    local trigger JASS_Test = CreateTrigger()
    call TriggerRegisterEnterRectSimple(JASS_Test,gg_rct_FootSwitch)
    call TriggerAddAction (JASS_Test,function Encounter_Set)
endfunction

does not work. However if I add to it (without disabling my trigger set up part) this trigger converted to custom text:

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    call Encounter_Set()
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Untitled_Trigger_001, gg_rct_FootSwitch )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction

It does, and for the life of me I don't understand why only that works, as my trigger setup and the custom trigger setup are practically the same. I tried it with a generated global name (i.e. gg_trg_JASS_Test), still doesn't work.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
I am sorry but I cannot recreate any problem in the test map. There is no reachable JASS code in the map.

When I put the whole code inside a trigger and save the map it is saved with a ROC extension (.w3m) and cannot be opened.
Probably the result of a syntax error? The function name templates do not match the trigger name you put them in so it will be trying to call an undeclared function.
 
Status
Not open for further replies.
Top