[ZScript] Weird results with local variables

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
D2JK
Posts: 545
Joined: Sat Aug 30, 2014 8:21 am

[ZScript] Weird results with local variables

Post 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'.
User avatar
Fishytza
Posts: 792
Joined: Wed Feb 23, 2011 11:04 am
Preferred Pronouns: They/Them
Contact:

Re: [ZScript] Weird results with local variables

Post 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); }
D2JK
Posts: 545
Joined: Sat Aug 30, 2014 8:21 am

Re: [ZScript] Weird results with local variables

Post by D2JK »

Huh, never thought of trying that... but you're right, thanks!
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49230
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] Weird results with local variables

Post by Graf Zahl »

Everything pointed out here should work correctly now
Post Reply

Return to “Closed Bugs [GZDoom]”