Jump to content
  • 0

Can you use conditionals in Decorate?


LoneC

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?

Edited by LoneC

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...