• Hey! Register here to create your account, engage with the community, and talk about what is new!

Need help with setting a variable

ERN468

New member
Joined
Sep 15, 2020
Messages
2
Reaction score
0
Code:
PlayerEventClickMenuSlot
IfGameEventItemEquals(Shears)
{
   IfVariable(%default money >= 100)
   {
      PlayerActionGiveItems(Shears)
      SetVariableSubtract(%default money, 100)
   }
}
else
{
   PlayerActionSendMessage("&cNot enough coins!")
   PlayerActionPlaySound(Experience Orb Pickup)
}

If you don't have enough money the code will correctly print out the message and play the sound. However, if you do have enough money the code will give you the shears but not subtract money from your total and I'm not sure why. Does anyone know why my code doesn't work?
 

DogWithHats

Forum adept
Overlord
Joined
Sep 9, 2020
Messages
335
Reaction score
53
yeah, that's an important distinction to make
theoretically, it is possible to decrement with set variable: subtract, but it's pointless if decrement exists, which it does
 

Vulcano

Forum adept
Overlord
Joined
Sep 11, 2020
Messages
243
Reaction score
65
The else seems to be in the wrong spot, it was running if the held item isnt shears, but you want it to run if %default money is less than 100.

Code:
PlayerEventClickMenuSlot
IfGameEventItemEquals(Shears)
{
   IfVariable(%default money >= 100)
   {
      PlayerActionGiveItems(Shears)
      SetVariableSubtract(%default money, 100)
   }
else
{
   PlayerActionSendMessage("&cNot enough coins!")
   PlayerActionPlaySound(Experience Orb Pickup)
}
}
 

General_Mudkip

Retired Moderator
Overlord
Joined
Sep 6, 2020
Messages
362
Reaction score
95
The else seems to be in the wrong spot, it was running if the held item isnt shears, but you want it to run if %default money is less than 100.

Code:
PlayerEventClickMenuSlot
IfGameEventItemEquals(Shears)
{
   IfVariable(%default money >= 100)
   {
      PlayerActionGiveItems(Shears)
      SetVariableSubtract(%default money, 100)
   }
else
{
   PlayerActionSendMessage("&cNot enough coins!")
   PlayerActionPlaySound(Experience Orb Pickup)
}
}

The else is in the wrong spot if you're thinking about traditional coding languages. In DF, the else is placed outside of the brackets so it would make sense here.
 

Vulcano

Forum adept
Overlord
Joined
Sep 11, 2020
Messages
243
Reaction score
65
The else is in the wrong spot if you're thinking about traditional coding languages. In DF, the else is placed outside of the brackets so it would make sense here.
i mean I think it is on the wrong conditional
 
Top Bottom