• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Local Integer Variable error

Status
Not open for further replies.
Well, JASS makes my head explode. I'm using it more and more and learn more and more, but I'm only using it as functions and custom script, not 100% fully JASS triggers.

Anyway, since a while back I've started to use local variables, because they're awesome so I don't have to declare 100 global ones. But I've encountered a problem, as always...

The thing is I get this error: "Expected a variable name" with this trigger:

  • JassTest
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • Custom script: local integer c = 0
      • Set p_group[0] = (All players controlled by a User player)
      • Player Group - Pick every player in p_group[0] and do (Actions)
        • Loop - Actions
          • Custom script: set c = c + 1
      • Custom script: call DestroyForce(udg_p_group[0])
What I've understand from my own knowledge, the
  • Custom script: set c = c + 1
is outside the "bounds" of the trigger, because the "Player Pick" action creates a new function. So how the hell do I declare a local variable inside a Player Pick and use it even after the Player Pick?!
 
  • Jass Test
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • Custom script: local integer c = 0
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) controller) Equal to User
            • Then - Actions
              • Custom script: set c = c + 1
            • Else - Actions
This is the same :]

P.S. I would also add this condition: "((Player((Integer A))) slot status) Equal to Is playing", but I don't know what you want it for.
 
This one works too:
  • Jass Test
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Custom script: local integer c = 0
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) controller) Equal to User
            • Then - Actions
              • Custom script: set c = c + 1
            • Else - Actions
 
I know, but then I can't use it after the player pick :) Anyway, I'll stick with a loop. May you tell me how to do an "and"-if with JASS? In most programming languages they are using "&&" as an "and"-if, but how do I use it in JASS? This isn't working:

  • JassTest
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • Custom script: local integer i = 0
      • Custom script: local integer c = 0
      • Custom script: loop
      • Custom script: if (GetPlayerController(ConvertedPlayer(i)) == MAP_CONTROL_USER) then && ( GetPlayerSlotState(ConvertedPlayer(i)) == PLAYER_SLOT_STATE_PLAYING ) then
      • Custom script: call DisplayTimedTextToForce( GetPlayersAll(), 5.00, "Player " + I2S(i+1) + "detected playing." )
      • Custom script: endif
      • Custom script: set i = i + 1
      • Custom script: exitwhen (i <= 12)
      • Custom script: endloop
 
Status
Not open for further replies.
Top