having a little trouble getting my ZScript to work

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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
TIIKKETMASTER
Posts: 12
Joined: Thu Jul 29, 2021 2:02 pm
Discord: CoolGames2022(TF2 DM's Open)#9185

having a little trouble getting my ZScript to work

Post by TIIKKETMASTER »

Hello, I am here to ask a question about ZScript. I think it is important that you know that I have never made anything with ZScript before, so please understand if I miss something obvious. Thank you.

So, basically what I am trying to do is make a dash in the game, but I keep getting this error near the start of my script, at precisely line 6.

here is the error:

Code: Select all

Script error, "doommod.pk3:zscript.txt" line 7:
Unexpected '{'
Expecting '=' or '*=' or '/=' or '%=' or '+=' or '-=' or '<<=' or '>>=' or '&=' or '|=' or '^=' or '>>>=' or '?' or '||' or '&&' or '==' or '!=' or '~==' or '<' or '>' or '<=' or '>=' or '<>=' or 'is' or '..' or '|' or '^' or '&' or '<<' or '>>' or '>>>' or '-' or '+' or '*' or '/' or '%' or 'cross' or 'dot' or '**' or '::' or ')'
and here is my code:

Code: Select all

class newplayer1 : doomplayer
{
void dash()
{
If(GetPlayerInput(MODINPUT_BUTTONS)&BT_SPEED
{
A_playsound("skeleton/swing")
A_ChangeFlag(nogravity,true)
A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE)
A_Setspeed(0.5)
25 ThrustThing(angle * 256 / 360, 20, 0, 0)
A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE)
A_ChangeFlag(nogravity,false)
A_Setspeed(1)
}
else
{
}
}
}
}
I am unsure as to what the problem is, and none of my theories had worked.

Theory 1 was that I had to remove the If and Else parts, but when I tried that, it still gave me the same error.
I then tried to remove the excess braces, but when I tried that, it still gave me the same error.
Lastly, I remembered that it said there was an unexpected opening brace, and to replace it with one of the many symbols on screen, but I wasn't sure which one I was supposed to use.

And that's what brought me here. anyone have any ideas on what my next course of action is? I'm practically stuck on this :cry: ... thanks in advance!
User avatar
m8f
 
 
Posts: 1397
Joined: Fri Dec 29, 2017 4:15 am
Discord: m8f#0629
Github ID: mmaulwurff
Location: Siberia (UTC+7)

Re: having a little trouble getting my ZScript to work

Post by m8f »

First, use indentation.
Second, the closing ")" is missing on your If line.
Third, there is an extra "}" at the end.
Forth, all your statement lines lack ";".

The properly formatted code will look like this:

Code: Select all

class newplayer1 : doomplayer
{
  void dash()
  {
    If(GetPlayerInput(MODINPUT_BUTTONS)&BT_SPEED)
    {
      A_playsound("skeleton/swing");
      A_ChangeFlag(nogravity,true);
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      A_Setspeed(0.5);
      25 ThrustThing(angle * 256 / 360, 20, 0, 0);
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      A_ChangeFlag(nogravity,false);
      A_Setspeed(1);
    }
    else
    {
    }
  }
}
User avatar
TIIKKETMASTER
Posts: 12
Joined: Thu Jul 29, 2021 2:02 pm
Discord: CoolGames2022(TF2 DM's Open)#9185

Re: having a little trouble getting my ZScript to work

Post by TIIKKETMASTER »

Thank you, M8f! I am no longer getting that error!

however, I am having another problem. It is line 11, in which it's error line states:
Script error, "doommod.pk3:zscript" line 11:
Unexpected identifier
Expecting ';'
any way to fix that line? my theory is that it is the '25' that is the problem, but I am unsure on how to go about that, as I need that break to be there in order for it to work properly. Your help will be greatly appreciated!
User avatar
m8f
 
 
Posts: 1397
Joined: Fri Dec 29, 2017 4:15 am
Discord: m8f#0629
Github ID: mmaulwurff
Location: Siberia (UTC+7)

Re: having a little trouble getting my ZScript to work

Post by m8f »

Yes, I haven't noticed it before. '25' is the culprit.

It seems that you want to add a delay inside a function. You cannot do this. The code inside a function is very different from defining duration in actor states.
User avatar
TIIKKETMASTER
Posts: 12
Joined: Thu Jul 29, 2021 2:02 pm
Discord: CoolGames2022(TF2 DM's Open)#9185

Re: having a little trouble getting my ZScript to work

Post by TIIKKETMASTER »

OK, I have removed that, but another problem is arising: It's just plain not working.

I have removed the '25', i added the quotes in between the 'nogravity' identifiers, I know for a FACT that it's not mapinfo, because it says right in the gameinfo that there is "playerclasses = 'newplayer1'", I also have my "run" bind to shift, so I also know that it isn't that.

I genuinely do not know what is going on. :(
User avatar
m8f
 
 
Posts: 1397
Joined: Fri Dec 29, 2017 4:15 am
Discord: m8f#0629
Github ID: mmaulwurff
Location: Siberia (UTC+7)

Re: having a little trouble getting my ZScript to work

Post by m8f »

I guess that you just defined a function that isn't called from anywhere. Like, where does this "dash()" is referred from?
User avatar
TIIKKETMASTER
Posts: 12
Joined: Thu Jul 29, 2021 2:02 pm
Discord: CoolGames2022(TF2 DM's Open)#9185

Re: having a little trouble getting my ZScript to work

Post by TIIKKETMASTER »

m8f wrote:I guess that you just defined a function that isn't called from anywhere. Like, where does this "dash()" is referred from?
I thought that the dash script is what is being called below, is it not? would I just be able to call it script 1 or something?
User avatar
m8f
 
 
Posts: 1397
Joined: Fri Dec 29, 2017 4:15 am
Discord: m8f#0629
Github ID: mmaulwurff
Location: Siberia (UTC+7)

Re: having a little trouble getting my ZScript to work

Post by m8f »

No, if it's all the code you've got, it's nothing to call this function.

Try this:

Code: Select all

class newplayer1 : doomplayer
{
  override
  void PlayRunning()
  {
    If(GetPlayerInput(MODINPUT_BUTTONS)&BT_SPEED)
    {
      A_playsound("skeleton/swing");
      bNogravity = true;
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      A_Setspeed(0.5);
      ThrustThing(angle * 256 / 360, 20, 0, 0);
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      bNogravity = false;
      A_Setspeed(1);
    }

    Super.PlayRunning();
  }
}
Note the "override" thing. There is a PlayRunning() function in PlayerPawn class (on which DoomPlayer is based), and it's declared virtual. This means that it can be overridden in inherited classes, including yours.

By overriding it, you add your new behavior. By calling Super.PlayRunning() you also keep the old behavior, so not to break anything.

In this version, this function is called when the player is running and Run button is pressed.

You will have to do some tweaking to make it dash - at the moment it makes the player stop for a moment.
User avatar
TIIKKETMASTER
Posts: 12
Joined: Thu Jul 29, 2021 2:02 pm
Discord: CoolGames2022(TF2 DM's Open)#9185

Re: having a little trouble getting my ZScript to work

Post by TIIKKETMASTER »

m8f wrote:No, if it's all the code you've got, it's nothing to call this function.

Try this:

Code: Select all

class newplayer1 : doomplayer
{
  override
  void PlayRunning()
  {
    If(GetPlayerInput(MODINPUT_BUTTONS)&BT_SPEED)
    {
      A_playsound("skeleton/swing");
      bNogravity = true;
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      A_Setspeed(0.5);
      ThrustThing(angle * 256 / 360, 20, 0, 0);
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      bNogravity = false;
      A_Setspeed(1);
    }

    Super.PlayRunning();
  }
}
Note the "override" thing. There is a PlayRunning() function in PlayerPawn class (on which DoomPlayer is based), and it's declared virtual. This means that it can be overridden in inherited classes, including yours.

By overriding it, you add your new behavior. By calling Super.PlayRunning() you also keep the old behavior, so not to break anything.

In this version, this function is called when the player is running and Run button is pressed.

You will have to do some tweaking to make it dash - at the moment it makes the player stop for a moment.
Thank you! I have removed the second A_ChangeVelocity as to make the player not stop. Last question, is how I would give it a cooldown so as to not make it easily spammable? because as of right now you are able to hold shift and basically fly, which is not what I'm looking for.
I remember that you can make it to where you have to have enough charge to be able to do it, but I'm not sure where I'd do that.
I was thinking of possibly adding something after BT_SPEED like "If(GetPlayerInput(MODINPUT_BUTTONS)&BT_SPEED & 'dashcharge'<35)" or something like that, I'm not sure. Yes I did read the wiki and no I couldn't find any information on adding more factors into that part.
User avatar
Sir Robin
Posts: 392
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: having a little trouble getting my ZScript to work

Post by Sir Robin »

TIIKKETMASTER wrote:Last question, is how I would give it a cooldown so as to not make it easily spammable? because as of right now you are able to hold shift and basically fly, which is not what I'm looking for.
I remember that you can make it to where you have to have enough charge to be able to do it, but I'm not sure where I'd do that.
I was thinking of possibly adding something after BT_SPEED like "If(GetPlayerInput(MODINPUT_BUTTONS)&BT_SPEED & 'dashcharge'<35)" or something like that, I'm not sure. Yes I did read the wiki and no I couldn't find any information on adding more factors into that part.
You can add a cooldown timer:

Code: Select all

class newplayer1 : doomplayer
{
  //store the dash cooldown time
  int dashcooldown;

  override
  void Tick()
  {
    //decrease the dash cooldown time each tick
    if (dashcooldown > 0) dashcooldown--;
 
    super.tick();
  }

  override
  void PlayRunning()
  {
    //add the cooldown check to the IF statement. Note that "&" is a binary AND and that "&&" is a logical AND
    If(GetPlayerInput(MODINPUT_BUTTONS) & BT_SPEED && dashcooldown <= 0)
    {
      //reset the cooldown
      dashcooldown = 35; // 35 ticks = 1 second, adjust as needed

      A_playsound("skeleton/swing");
      bNogravity = true;
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      A_Setspeed(0.5);
      ThrustThing(angle * 256 / 360, 20, 0, 0);
      A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
      bNogravity = false;
      A_Setspeed(1);
    }

    Super.PlayRunning();
  }
}
And if you still want to have part of the code delayed, you can add a timer for that as well. I break it into functions, I think it's easier to read, but write it how it works for you.

Code: Select all

class newplayer1 : doomplayer
{
  int dashcooldown;
  int dash2timer;

  override
  void Tick()
  {
    if (dashcooldown > 0) dashcooldown--;

    //check the dashtimer and decrease it. If it hits zero then call the second part of the dash function
    if (dash2timer > 0)
    {
      dash2timer--;
      if (dash2timer == 0) DashPart2();
    }

    super.tick();
  }

  override
  void PlayRunning()
  {
    If(GetPlayerInput(MODINPUT_BUTTONS) & BT_SPEED && dashcooldown <= 0)
    {
      dashcooldown = 35;

      //start the dash
      DashPart1();
    }

    Super.PlayRunning();
  }

  void DashPart1()
  {
    A_playsound("skeleton/swing");
    bNogravity = true;
    A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
    A_Setspeed(0.5);

    //this will set the timer for the second part
    Dash2Timer = 25;
  }

  void DashPart2()
  {
    ThrustThing(angle * 256 / 360, 20, 0, 0);
    A_ChangeVelocity(0,0,0,CVF_RELATIVE|CVF_REPLACE);
    bNogravity = false;
    A_Setspeed(1);
  }
}

Return to “Scripting”