Random Value - Squiffy

RVS

a


felixp7

The help page about setting and getting attributes includes instructions on how to do it from Javascript. In your case:

if (i < 9)
    squiffy.set("money", squiffy.get("money") - 5);

I haven't tested this, hope it works. Good luck!


RVS

a


thetruespin

I don't believe you can put the @dec within an else statement. I could be wrong, but I suspect that's why it's being executed regardless.

Sadly the conditional logic in Squiffy using Markdown is quite limited.

The fix would be to deal with the reduction in cash via javascript prior to your if else statement. I'd have a javascript variable for money, and a corresponding squiffy attribute. All modifications to the sum would be first calculated in JS, and then the JS variable converted to the standard Squiffy attribute, which you can output with the standard {myattribute} call.

So basically you keep all calculations within the JS element, and the Squiffy attribute is simply updated to match.


thetruespin

I threw this together. In this example it's basically a 50/50 chance rather than 1 in 10, but the principle is the same.

    var money = 70;
    var x = Math.floor(Math.random() * 2 + 1);
    
    if (x===1)
    {
    var money = money
    }
    else if(x===2)
    {
    var money = money - 6
    }
    squiffy.set("mymoney", money);
    squiffy.set("mynumber", x);

{if mynumber=1:Congrats! Because you were the 100th customer that day, you won a free burrito! It tasted delicious, because free food always tastes better. You spent no money and still have ${mymoney}.}{else:You spent $6 on a burrito. Yum. You now have ${mymoney}} 
<br><br>
[Continue]  

I tested the above and it works fine.

  • First we set two JS variables, money and x.
  • We generate a random number between 1 and 2 and set this as x.
  • A basic if/else statements then either decreases or leaves our money variable the same (depending on the value of x).
  • We then take our two javascript variables and convert them into Squiffy attributes, which we can now access via Markdown
  • Your section code then works as expected.

It's important to remember that if you're using this method regularly during your game, you'll need to ensure that your Squiffy attribute mymoney and your Javascript variable are kept in sync. This can easily be accomplished using:

var money = squiffy.get("mymoney");

RVS

Thanks!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums