Page 1 of 1

[ZScript] Weird results with local variables

Posted: Fri Nov 11, 2016 12:28 pm
by D2JK

Code: Select all

Class NewPlayer : DoomPlayer
 {
  Default
   {
    Player.StartItem "NewPistol";
    Player.StartItem "Clip", 50;
    Player.WeaponSlot 2, "NewPistol";
   } 
 }



Class NewPistol : Pistol
 {
  int testing;
  States
   {
    Select:
     TNT1 A 0  {  invoker.testing = 9;  }
     Goto Super::Select;
    Fire:
     TNT1 A 0 A_ChangeVelocity(0,0, testing);
//   TNT1 A 0 A_ChangeVelocity(0,0, invoker.testing);
     SHTG A 35 A_LogInt(testing);	 
//   SHTG A 35 A_LogInt(invoker.testing);
     Goto Ready;
   }
 }
This will log "0" (zero) in the console, and A_ChangeVelocity has no effect. In my actual mod, the number logged in the console is random and very large (sometimes negative), such as 217 990 448.

If you try to use the two lines currently commented out, it should give an error message on startup: Unknown identifier 'invoker'.

Re: [ZScript] Weird results with local variables

Posted: Fri Nov 11, 2016 5:00 pm
by Fishytza
D2JK wrote:If you try to use the two lines currently commented out, it should give an error message on startup: Unknown identifier 'invoker'.
If you put curly brackets around them then it works just fine.
(like so)

Code: Select all

{ A_ChangeVelocity(0,0, invoker.testing); }
{ A_LogInt(invoker.testing); }

Re: [ZScript] Weird results with local variables

Posted: Fri Nov 11, 2016 7:34 pm
by D2JK
Huh, never thought of trying that... but you're right, thanks!

Re: [ZScript] Weird results with local variables

Posted: Sat Nov 12, 2016 8:22 am
by Graf Zahl
Everything pointed out here should work correctly now