ZScript/Decorate Problem with going to a state

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

ZScript/Decorate Problem with going to a state

Postby Soosisya » Mon Jan 04, 2021 2:53 am

I have a script for a pistol. It should loop in one state until the variable reaches 0 and then go to the next state. The thing is it never goes to the next state no matter what (even if I change the conditions). I remember having similar problems like 10 years ago. What's the problem with my script?
Code: Select allExpand view
Class RPistol Pistol replaces Pistol
{
 
int dmgcritdur;
 
States
 
{
  
Fire:
    
PISG A 0 {invoker.dur 3;}
    
PISG A 1
    
{
     
A_JumpIf(invoker.dur == 0"Fire2");
     
invoker.dur--;
    }
    Goto 
Fire+1;
    
Fire2:
    
PISG B 6
    
...  
Soosisya
 
Joined: 31 Oct 2020

Re: ZScript/Decorate Problem with going to a state

Postby Jarewill » Mon Jan 04, 2021 3:07 am

Jumps work differently in anonymous functions.
Try this:
Code: Select allExpand view
Class RPistol : Pistol replaces Pistol
{
 int dmg, crit, dur;
 States
 
{
  Fire:
    PISG A 0 {invoker.dur = 3;}
    PISG A 1
    
{
     If(invoker.dur == 0){ Return ResolveState("Fire2"); }
     invoker.dur--;
    }
    Goto Fire+1;
    Fire2:
    PISG B 6
    
...
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: ZScript/Decorate Problem with going to a state

Postby Soosisya » Mon Jan 04, 2021 3:19 am

Jarewill wrote:Jumps work differently in anonymous functions.
Try this:
Code: Select allExpand view
Class RPistol : Pistol replaces Pistol
{
 int dmg, crit, dur;
 States
 
{
  Fire:
    PISG A 0 {invoker.dur = 3;}
    PISG A 1
    
{
     If(invoker.dur == 0){ Return ResolveState("Fire2"); }
     invoker.dur--;
    }
    Goto Fire+1;
    Fire2:
    PISG B 6
    
... 


It doesn't seem to work:
Script error, "RiskOfDoom.pk3:weapons" line 9:
Return type mismatch
Soosisya
 
Joined: 31 Oct 2020

Re: ZScript/Decorate Problem with going to a state

Postby Jarewill » Mon Jan 04, 2021 4:35 am

Right, forgot about that.
Try this:
Code: Select allExpand view
Class RPistol Pistol replaces Pistol
{
 
int dmgcritdur;
 
States
 
{
  
Fire:
    
PISG A 0 {invoker.dur 3;}
    
PISG A 1
    
{
     If(
invoker.dur == 0){ Return ResolveState("Fire2"); }
     Else{ Return 
ResolveState(null); }
     
invoker.dur--;
    }
    Goto 
Fire+1;
    
Fire2:
    
PISG B 6
    
...  
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: ZScript/Decorate Problem with going to a state

Postby Soosisya » Mon Jan 04, 2021 4:39 am

Jarewill wrote:Right, forgot about that.
Try this:
Code: Select allExpand view
Class RPistol : Pistol replaces Pistol
{
 int dmg, crit, dur;
 States
 
{
  Fire:
    PISG A 0 {invoker.dur = 3;}
    PISG A 1
    
{
     If(invoker.dur == 0){ Return ResolveState("Fire2"); }
     Else{ Return ResolveState(null); }
     invoker.dur--;
    }
    Goto Fire+1;
    Fire2:
    PISG B 6
    
...

Nope. Still the same error. It seems like "return" can't return the string, or something like that
Soosisya
 
Joined: 31 Oct 2020

Re: ZScript/Decorate Problem with going to a state

Postby Jarewill » Mon Jan 04, 2021 4:49 am

I was just being stupid and forgot to move the invoker.dur--; too.
This should work now:
Code: Select allExpand view
    PISG A 1
    
{
     If(invoker.dur == 0){ Return ResolveState("Fire2"); }
     Else{ invoker.dur--; Return ResolveState(null); }
    }
Jarewill
 
 
 
Joined: 21 Jul 2019

Re: ZScript/Decorate Problem with going to a state

Postby Soosisya » Mon Jan 04, 2021 4:51 am

Jarewill wrote:I was just being stupid and forgot to move the invoker.dur--; too.
This should work now:
Code: Select allExpand view
    PISG A 1
    
{
     If(invoker.dur == 0){ Return ResolveState("Fire2"); }
     Else{ invoker.dur--; Return ResolveState(null); }
    

Now it works! Thanks a lot!
Soosisya
 
Joined: 31 Oct 2020


Return to Scripting

Who is online

Users browsing this forum: No registered users and 3 guests