incredibly basic jass question

Rep7a

Member
Reaction score
2
I'm just starting learning jass, so i've been looking at beginning jass guides, and the one i found told me to start like this:

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
call DisplayTimedTextToForce( GetPlayersAll(), 30, "hello" )
endfunction

now it appears everytime i go to test the map, it takes me to the warcraft main menu, why is this? (very noobish question, i appologize :p)
 

luorax

Invasion in Duskwood
Reaction score
67
That function is okayish - not that efficient, but it should not cause error.
You should post the whole trigger to see what's wrong.
 

Rep7a

Member
Reaction score
2
again i'm just starting out :p And that is the whole trigger, am i wrong for only having that much?
 

luorax

Invasion in Duskwood
Reaction score
67
That does not do anything :D

It should be something like this:

JASS:
function Test takes nothing returns nothing
    call DisplayTimedTextToForce( GetPlayersAll(), 30, "hello" )
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Test, function Test )
endfunction


Note that the name of the trigger must be "Test" in order to get this work.
And also, there's a field over the converted JASS script, called "Run at Map Initialization". Check that.
 

Rep7a

Member
Reaction score
2
Oh, awsome! Thanks, hey if it's not too much to ask you wouldn't happen to have xfire or anything like that would you? I'm looking to learn these things and will more than likely have more questions :p
 

inevit4ble

Well-Known Member
Reaction score
38
try a save before you test. If you're running jngp you always have to save BEFORE you test
 

Rep7a

Member
Reaction score
2
thanks guys! Although i ran into another problem, as i said i'm just starting out, so i'm testing a few things i've learned and i ran into a problem, my trigger looks like this.

JASS:
function Test takes player p returns nothing
    local integer i = 0
    local player p = Player(0)
    loop
        exitwhen i==10
        call DisplayTextToPlayer(p, 0,0, "Hello, world! "+I2S(i))
        set i=i+1
    endloop
endfunction
//====================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerAddAction(gg_trg_Test , function Test)
    endfunction

The error i'm getting is "function Test must not take any arguments when used as code" I understand the error, i just don't know why i'm getting it :p
 

luorax

Invasion in Duskwood
Reaction score
67
JASS:
function Test takes player p returns nothing
    local integer i = 0
    local player p
    loop
        exitwhen i==10
        set p=Player(i)
        call DisplayTextToPlayer(p, 0,0, "Hello, world! "+I2S(i))
        set i=i+1
    endloop
    set p=null
endfunction
function TestAction takes nothing returns nothing
    call Test(GetTriggerPlayer())
endfunction
//====================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerAddAction(gg_trg_Test , function TestAction )
endfunction
 

Dirac

22710180
Reaction score
147
JASS:
function Test takes nothing returns nothing
    local integer i = 0
    local player p
    loop
        exitwhen i==10
        set p=Player(i)
        call DisplayTextToPlayer(p, 0,0, "Hello, world! "+I2S(i))
        set i=i+1
    endloop
    set p=null
endfunction
//====================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerAddAction(gg_trg_Test , function Test)
endfunction
avoid useless function calling, also why does the Test function takes player p if p is a declared local, that's even set inside the function to another value
 

luorax

Invasion in Duskwood
Reaction score
67
True, but your example does not represent how function calling and "takes" work.
 

ZakkWylde-

New Member
Reaction score
14
I believe luorax addressed an issue different to your problem with:

JASS:
function Test takes player p returns nothing
    local integer i = 0
    local player p
    loop
        exitwhen i==10
        set p=Player(i)
        call DisplayTextToPlayer(p, 0,0, "Hello, world! "+I2S(i))
        set i=i+1
    endloop
    set p=null
endfunction
function TestAction takes nothing returns nothing
    call Test(GetTriggerPlayer())
endfunction
//====================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerAddAction(gg_trg_Test , function TestAction )
endfunction

If you want the function to be called with TriggerAddAction, make sure the function takes nothing and returns nothing, as it says.
In this case, you do not need the function to "takes player p". Change that to "takes nothing".

When the function takes player p, it is looking for an input from whence it was called. In luroax's case, he put GetTriggerPlayer() as the input. But it doesn't seem like your Hello World function requires a particular player.
You are looping through all (11) players anyways.
[For future reference, if your function takes <something>, then you do not need to declare "local <something>" in the function. Simply use <something> as if it were already declared. But THIS IS NOT YOUR PROBLEM.]

Just change "takes player p" to "takes nothing" and you should be good.

[and it seems somebody has already posted this--and that I am blind. anyways, maybe this will be more clear]
 

luorax

Invasion in Duskwood
Reaction score
67
[For future reference, if your function takes <something>, then you do not need to declare "local <something>" in the function. Simply use <something> as if it were already declared. But THIS IS NOT YOUR PROBLEM.]

Ehh, that's true. I did not pay enough attention, I missed that the player variable it takes is p, and tried to declare it once again - my code won't work. Also, if your function takes a handle type variable (like "player p"), you don't have to null it - they will be nulled automatically.

Also, the most efficient way to this would look like this:

JASS:
function TestAction takes nothing returns boolean
    local player p
    local integer i = 0
    loop
        exitwhen i&gt;11
        set p=Player(i)
        call DisplayTextToPlayer(p, 0,0, &quot;Hello, world! &quot;+I2S(i))
        set i=i+1
    endloop
    set p=null
    return false
endfunction
//====================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerAddCondition(gg_trg_Test , Condition(function TestAction ))
endfunction


You may think "A condition as function? lolwut?" - yes, in this example the trigger itself (the handle) will NEVER fire, however each function in the condition part will be executed - this is way faster than using actions, as they fire the trigger, etc etc (however in Condition functions you can not use TriggerSpellAction/PolledWait)

If you decide to go this way, your function must return a boolean. The returned boolean determines whether the trigger is fired or not. Because we don't want our trigger to be fired, simply add a "return false" to the end of the function. That way the trigger itself will never fire, but each function before the return part will be exucuted.
 

Dirac

22710180
Reaction score
147
yea that's about what i posted but using conditions instead, which are faster, but harder to understand to beginner JASS users. I don't recommend JASS over vJass at all, vJass is JASS but "organized"
 

ZakkWylde-

New Member
Reaction score
14
Wow I never knew this about conditions. Very cool. Are there any other limitations on what can be done using this method?


On another note, this may help you understand in what case you could use a function that
JASS:
takes &lt;something&gt;
. (It may have a few typos, but I think it is pretty solid--useless maybe, but solid :D)
JASS:
function Test takes player p returns nothing
        local integer i = GetPlayerId(p) //this is only necessary for the I2S display...
        call DisplayTextToPlayer(p, 0,0, &quot;Hello, world! &quot;+I2S(i))
endfunction

function TestAction takes nothing returns nothing
    local integer i = 0
    loop
    exitwhen i &gt; 10 //Test will be called 11 times, once for each player, from 0 to 10.
         call Test(Player(i)) //note that we are calling the function above with a parameter that we input: Player(i) -- because Test() is looking for a player, and then it uses that player to complete an action.
         set i = i +1
    endloop
endfunction
//====================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerAddAction(gg_trg_Test , function TestAction )
endfunction


But now that I think about it, wouldn't it just be fastest (i.e., simplest to type) to:

JASS:
function Test takes nothing returns nothing
     call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, &quot;Hello, world! &quot; + I2S( GetPlayerId(GetLocalPlayer()) ) )
endfunction
//====================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger()
    call TriggerAddAction(gg_trg_Test , function Test)
endfunction


I'm interested :D
 

luorax

Invasion in Duskwood
Reaction score
67
It'd be even faster with a Condition :)

Also, it should be [ljass]exitwhen i > 11[/ljass] - actually we have 12 players, 12-1=11.
 

ZakkWylde-

New Member
Reaction score
14
It'd be even faster with a Condition :)

Also, it should be [ljass]exitwhen i > 11[/ljass] - actually we have 12 players, 12-1=11.

[ljass]exitwhen i > 10 //Test will be called 11 times, once for each player, from 0 to 10.[/ljass]
I used 10 because I figured from his example that he had 11 players.

Anyways, good looking out :p

EDIT: actually, now that I look, the original function only calls from Player(0) to Player(9) because it exits the loop before running for Player(10). ANYWAYS...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top