Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
LoneC

Can you use conditionals in Decorate?

Question

I am making a melee weapon and I want to make it so there is a 1/3 chance of having a 'critical hit'

So I want something like

 

    Fire:

    if(random(0, 100) < 33) {

        // Critical hit

    }

    else {

        // Regular hit

    }

    Goto Ready

 

However I keep getting a "Sprite must be four characters long" error.

Do if statements exist in decorate? How come the "if" lights up like a keyword in slade 3.0?

If the if statements don't exist, then how can I achieve this effect?

Share this post


Link to post

3 answers to this question

Recommended Posts

  • 1

You're in the state definition part, and you don't define a state. That's your problem.

 

It looks like what you're trying to make is an anonymous function. I invite you to read the documentation.

 

Alternatively, each instruction can be on separate states, using an A_Jump function instead of your if.

Share this post


Link to post
  • 0
Posted (edited)
3 hours ago, Gez said:

You're in the state definition part, and you don't define a state. That's your problem.

 

It looks like what you're trying to make is an anonymous function. I invite you to read the documentation.

 

Alternatively, each instruction can be on separate states, using an A_Jump function instead of your if.

Is it possible to use Goto inside the anon function?

Share this post


Link to post
  • 0
3 hours ago, Gez said:

You're in the state definition part, and you don't define a state. That's your problem.

 

It looks like what you're trying to make is an anonymous function. I invite you to read the documentation.

 

Alternatively, each instruction can be on separate states, using an A_Jump function instead of your if.

I got it to work now actually thanks to you. I used a simple anon function. Here is the code for it. (I don't have sprites for it yet so I used the shotgun sprite for testing).

 

        SHTG A 0 {
            if(random(0, 100) < 33) {
                return state("Crit");
            }
            else {
                return state("Regular");
            }
        }
        Goto Ready 
            
        Regular:
        SHTG A 10 
        SHTG A 1 A_CustomPunch(random(1, 3) * 2, FALSE, 0) 
        SHTG A 3 
        Goto Ready
        
        Crit:
        SHTG B 20
        SHTG B 1 A_CustomPunch(random(1, 3) * 50, FALSE, 0) 
        SHTG A 3 
        Goto Ready 

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×