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
Veteran
Joined
Mar 16, 2012
Messages
155
Reaction score
164
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

Veteran
Veteran
Joined
Mar 30, 2012
Messages
617
Reaction score
3,705
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
45,996
Reaction score
16,806
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,241
Reaction score
5,114
First Language
EN, FR
Primarily Uses
RMMZ
Even the smart use stackoverflow.com lol
 

Latest Threads

Latest Profile Posts

1iVi6I.png


Continuing our countdown with Capsule Monster #13 Tomey Thomas! I loved the idea of a tiny book gaining sentience and being a little wizard. It’s a shame none of his spells are useful XD
Have to be more organised and serious. It helps that im running out of time at work :|. so much to do. Trying to make game studio professional. www.bmpgames.com
imgur links are back!
now I CAN keep getting away with NOT replacing them with updated renders!
yay!
I forgot RPG Maker even existed. Such good memories. Might boot up steam and download MV one more time
10 pieces of KFC chicken for US$12.30, delivery included. Cheap or expensive? :aswt:

Forum statistics

Threads
131,550
Messages
1,220,776
Members
173,220
Latest member
ZecaVn
Top