Triacular

Villager
Member
Joined
Jan 13, 2019
Messages
27
Reaction score
5
First Language
English
Primarily Uses
RMVXA
So I was working on the shop steal script, adding a switch based event.
The consequences worked perfectly without the if statements. I have been working on this code for a while now, and adding else doesn't work.
The problem is that the 2nd if statement is activates regardless weather or not switch 6 is on.
Does anyone know how to fix this?

Code:
  def do_steal(number)
    if $game_switches[6] = false
      life_or_death = rand(100)
      if life_or_death <= 50
        $game_party.gain_item(@item, 1)
      else
        $game_switches[21] = true
        SceneManager.goto(Scene_Map)
      end
    end
   
    if $game_switches[6] = true
      $game_switches[22] = true
      SceneManager.goto(Scene_Map)
    end
  end
 

DrDhoom

Monkey Needs a Hug
Regular
Joined
Mar 16, 2012
Messages
156
Reaction score
165
First Language
Indonesian
Primarily Uses
N/A
Because you've assigned the switch value instead of checking whether it's true or false.
The symbol for EQUAL TO is "==", so change your if statement to something like this:
Code:
if $game_switches[6] == false
 

Triacular

Villager
Member
Joined
Jan 13, 2019
Messages
27
Reaction score
5
First Language
English
Primarily Uses
RMVXA
Because you've assigned the switch value instead of checking whether it's true or false.
The symbol for EQUAL TO is "==", so change your if statement to something like this:
Code:
if $game_switches[6] == false

Thanks! Consequences are now working perfectly now! It was just a common and tiny mistake.
To think of it, I wonder why the editor doesn't point out errors like this.
 

OmnislashXX

Regular
Regular
Joined
Mar 30, 2012
Messages
746
Reaction score
3,871
First Language
English
Primarily Uses
RMMV
It assumes that we are not dumb. B)
 

Shaz

Keeper of the Nuts
Global Mod
Joined
Mar 2, 2012
Messages
46,153
Reaction score
16,970
First Language
English
Primarily Uses
RMMV
The editor doesn't point out the error because it's not an error - at least not a syntax error. You used the assignment operator, which is a valid operator, even in an if statement.

if $game_switches[6] = false will always return true, because the value of false was successfully assigned to $game_switches[6].

The editor assumed you were trying to assign a value, and check if it was successful or not. It's not a mind-reader - it doesn't know you were trying to check the value. It has to go on what you tell it, and you told it to assign, not compare.

Because $game_switches elements will always be true or false, you don't even need to do the == true or == false. You can just do this:
if $game_switches[6]
which will return true or false, whatever the switch is set to.

So if you want to do something if the switch is on, do this:
if $game_switches[6]

and if you want to do something if the switch is off, do this:
if !$ game_switches[6]

! is the "not" operator, and returns the opposite of whatever is in the switch.


Even the smart make mistakes that they cant figure out.
And that is why there is a forum :)
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
4,259
Reaction score
5,152
First Language
EN, FR
Primarily Uses
RMMZ
Even the smart use stackoverflow.com lol
 

Latest Threads

Latest Profile Posts

Curiosity kills cats. Not people. Remain ever curious!
"You dont have to negotiate if they dont have a hostage" :kaopride:
sketch1701194888871.png
Spiffing up maps is actually a lot of fun.
So the concept for my Game Jam project is way more than I can complete before the deadline. But I think I found a way to get the core done and make the incomplete parts either not really noticeable or make them a part of the story for now. That sneaky, dastardly Krampus! Then I can complete the rest. Did I mention that this is fun?

Forum statistics

Threads
136,551
Messages
1,267,446
Members
180,225
Latest member
Stormswinds
Top