Warcraft III resources & community, 2003–2006 · archived

JASS Tutorial

66 posts
#46
Ok so i have some globals:


set udg_GBA[0] = 0
set udg_GBA[1] = udg_GBA[0]
set udg_GBA[2] = (udg_GBA[1] / udg_GBA[0])
loop
exitwhen(udg_GBA[0] < ((-1)))
set udg_GBA[udg_GBA[1]] = R2S(S2I(0.10))
call TriggerSleepAction(I2R(udg_GBA[1]))
set udg_GBA[1] = (udg_GBA[1] / udg_GBA[1] + 1)
endloop


Ignore that its totaly useless, and that the loop never ends :P. And that udg_GBA[1] is always 0,1,2.

The point is, i cant just call it like:


set udg_GBA = 0
loop
exitwhen(udg_GBA > 0)
set udg_GBA = (R2S(S2I(0.10))
call TriggerSleepAction(udg_GBA)
endloop


Also as useless as the last function, only good for making great lag :P and an infinite useless trigger. But is this one impossible?
#47
Don't give silly functions that don't have :? any kind of sense, give me a spell that you don't understand or you want to know how it works, then I'll explain you 'what you want', but not so. So give me a func :D
#48
Alright, I'm new at JASS coding. I can do trigger-enhanced spells pretty well, so I decided to pick this up. I decided to give Daelin's mass-sleep JASS a shot, and I've got a slight problem. He says, "Make this the only and first spell made," In refrence to the raw code. I...uhh...didn't. Is there any way to check what the raw code is for this spell, or any way to set it to what I know it will be? If so, thanks.

Edit: Scratch that! Upon rereading the tutorial my 5th, 6th time i noticed that handy-dandy little "Convert to custom text" thing....hehe...That's what you get for reading an English book AND this... :lol:
#49
Whats wrong with this, its just a test trigger for using locals

the errors I get only contains the ones with the
local a, what to I do wrong?

Is the only problem that the local is after the first function?

function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing
    set a = ( a + "1" )
    call DisplayTextToForce( GetPlayersAll(), a )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_003 = CreateTrigger(  )
    local string a
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_003, 1.00 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_003, function Trig_Untitled_Trigger_003_Actions )
endfunction
#50
Well, your problem is more than obvious. Locals are visible (can be used) only in the function in which you declare them, not trigger. Conclusion? Your code should look like this:

function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing 
local string a
set a = ( a + "1" ) 
call DisplayTextToForce( GetPlayersAll(), a ) 
endfunction 

//=========================================================================== 
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing 
set gg_trg_Untitled_Trigger_003 = CreateTrigger( ) 
call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_003, 1.00 ) 
call TriggerAddAction( gg_trg_Untitled_Trigger_003, function Trig_Untitled_Trigger_003_Actions ) 
endfunction


Oh, and be careful, you must declare locals in a function BEFORE doing anything else. For example, in your section function you did this:

set gg_trg_Untitled_Trigger_003 = CreateTrigger( ) 
local string a


INCORRECT! Setting a value to a variable is also an action. This is correct:

local string a
set gg_trg_Untitled_Trigger_003 = CreateTrigger( )


Hope this helped!

~Daelin
#51
When u have local vars that you won't set again and u'll only use as data locals,you can set them right when u make them.So:

local string a 
set a = ( a + "1" )

turns to:

local string a=a+"1" //Or a=a+I2S(1)

Not nessecery but it's good to arrange your script.
#55
1. Don't triple post
2. This is not JASS. I'm not here to answer questions not related to the tutorial.

~Daelin
#56
3. Wrong link for the image. :P
#57
How do you determine "take" and "return" values for a function?
#58
For Blizzard functions? Use Jass Shop Pro!

~Daelin
#59
So basically in the sidebar with all the actions, I put the take and return values for those into the function? And what if a function has more than one action, then do you put the take and return values for all of them? And if so, and there are two of the same take or return values, do you leave it as one, or put two in?
#60
The rest of Daelin's original post has been moved to its own topic :wink: