Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Sugarcube]If command look for specific value from a list.

edited October 2015 in Help! with 2.0
So I'm trying to create an inventory system, but the way I'm doing it I need to have an if command look for a specific value of a Item list. How can I make an if command check to see if a variable equals anything from a list?
<<if $Inv_slot1 is ["Stick", "Soda", "Coins"]>>
<<else>> <<set $Inv_slot1 to "Stick">>
<</if>>
This is how my code looks like, of course the code is way bigger and messier but this is the baseline i need help with.
I've tried these ways too but again, they don't work.
<<if $Inv_slot1 is "Stick" "Soda" "Coins">>
<<if $Inv_slot1 is "Stick" or "Soda" or "Coins">>

The inventory system I'm making is following a Table setup
|!$Inv_slot1|!$Inv_slot2|$Inv_slot3|
|!$Inv_slot4|!$Inv_slot5|!$Inv_slot6|
And I'm trying to make a system that when I get an item, it will automatically place the item on whichever variable is not occupied with an item. However, since I cannot make a 'list' for the if command to look in this setup fails. So I need help on how to make a list that a if command can look for, as I've had multiple features that I've been unable to implement because I don't know how to do this.

Here's how I've done my 'checker' for soda. In-case it makes it easier to understand what I'm trying to do.
/* Soda Check */
<<if $Soda is 1>>

<<if $Soda_check is 1>> <<else>>
<<if $Inv_slot1 is ["Stick", "Soda", "Coins"]>> <<else>>
<<set $Inv_slot1 to "Soda"; $Soda_check to 1>> <</if>> <</if>>

Comments

  • You could simply use the boolean or operator to join sub-expressions. For example:
    <<if $Inv_slot1 is "Stick" or $Inv_slot1 is "Soda" or $Inv_slot1 is "Coins">>…
    

    If you really wanted to use an array, then what you're looking for is the <Array>.contains() method. For example:
    <<if [ "Stick", "Soda", "Coins" ].contains($Inv_slot1)>>…
    

    Either method will yield true if the value of $Inv_slot1 is one of Stick, Soda, or Coins.
Sign In or Register to comment.