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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top