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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×