Jump to content


Photo

How to check if a switch is true or false?

rpg maker vx ace switches check

  • Please log in to reply
10 replies to this topic

#1 chessplayerjames

chessplayerjames

    Member

  • Members
  • 12 posts
  • Primarily UsesRMXP
  • First LanguageEnglish

Posted 24 May 2012 - 05:45 PM

Hello RPG Maker forums,

I have a script request on how to check if my switch is true or not.  You would think that I would've easily found this, but not so, I can't seem to make it work.  Here's what I have so far, but it obviously won't work...


Spoiler


Basically, if Switch 1 is On, I want the default battle system to be set to :yctb and if it's off, I want it set to :dtb.  I'm sure it's really simple, but there's just something I'm missing.  I want it all done via scripting, don't want any event calls or anything.

Thanks for any and all help,
James

#2 PK8

PK8

    Close the window.

  • Members
  • 455 posts
  • LocationStanding on the backs of angels
  • Primarily UsesRMXP
  • First LanguageEnglish

Posted 24 May 2012 - 05:52 PM

That first line should be:
if $game_switches[1] == true


Yet another derp moment. :P

Edited by PK8, 24 May 2012 - 06:46 PM.

Single-handedly putting an end to the monopolisation of the scripting forums. Proud member of The Underground and JIFZ-NFPZ.
pk8.png fb.png tw.png yt.png

Have you ever wanted to attach switches, variables, and various information onto your Actors, Events, Classes, Skills, Armors, Items, Weapons, and Skills? Now you can. The Self Data Suite -- The Most Extensive Set of Scripts Around (also available for RPG Maker XP and VX)

#3 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 4,380 posts
  • LocationAustralia
  • Primarily UsesN/A

Posted 24 May 2012 - 06:39 PM

You can also shorten that to
if $game_switches[1]

or, for false,
if !$game_switches[1]


#4 chessplayerjames

chessplayerjames

    Member

  • Members
  • 12 posts
  • Primarily UsesRMXP
  • First LanguageEnglish

Posted 25 May 2012 - 07:42 AM

Sorry I wasn't more specific on the problem. This is the error I get if I do what I posted above:

Spoiler


This is the page to the original script I used.

And here's the script...


Spoiler


Sorry, the above code isn't split into lines...

Thanks for any and all help,
James

EDIT: In the above code, I only showed down to where it says after this line, don't edit.
EDIT2: In the above code, I shortened it so it only shows from the beginning to the line that sets the Default Battle System.
EDIT3: Is there something I have to call, or a class or def I have to initialize or whatever before I get to this line? That might be the problem.

Edited by chessplayerjames, 25 May 2012 - 07:45 AM.


#5 mobychan

mobychan

    CodeMaster

  • Members
  • 308 posts
  • LocationBaden-Würrtemberg - Germany
  • Primarily UsesRMVX Ace
  • First LanguageGerman

Posted 25 May 2012 - 08:53 AM

So you want to test the switch in the settings area?
That won't work since it's not inside a method.
You can only set variables/constants out of methods.
You'd have to search for the place where the script asks for the DEFAULT_BATTLE_SYSTEM and decides what to do.
At least that's what I guess before looking at it in detail
Posted Image
Posted Image
Supporting
Spoiler

#6 Gadwin

Gadwin

    Member

  • Members
  • 17 posts
  • LocationManila, Philippines
  • Primarily UsesRMVX Ace
  • First LanguageFilipino

Posted 25 May 2012 - 01:03 PM

why dont you just use the default change system code coded by yanfly for example

if $game_switches[1]
$game_system:set_battle_system(:ftb)

else
$game_system:set_battle_system(:dtb)

end

#7 chessplayerjames

chessplayerjames

    Member

  • Members
  • 12 posts
  • Primarily UsesRMXP
  • First LanguageEnglish

Posted 25 May 2012 - 01:48 PM

Sorry, maybe I still wasn't specific enough. I was trying to change the default battle system where it asked for it, but the problem is

if $game_switches[1]

That's the line where the error occurs, and I think it's the

[1]

Don't know what that has to do with it, but that's where the error is thrown.

#8 chessplayerjames

chessplayerjames

    Member

  • Members
  • 12 posts
  • Primarily UsesRMXP
  • First LanguageEnglish

Posted 30 May 2012 - 08:01 AM

Bump. I thought checking for switches should've been really easy? What am I doing wrong? (Look in the above error).

Thanks for any and all help,
James

#9 Chaos17

Chaos17

    Advanced Member

  • Early Adopter+
  • 489 posts
  • LocationFrance
  • Primarily UsesRMVX Ace
  • First LanguageFrench

Posted 30 May 2012 - 12:49 PM

Yeah, in test mode just press F9.
You will see a list of switch and variables.

If you want to use 2 different battle system, I recommend using this script, it will allow you to do it : Multiple Battle Systems
"This script allows you to create multiple battle managers that may have their own unique set of battle logic. Different battle scenes with their own battle windows can be added as well."

Edited by Chaos17, 30 May 2012 - 12:56 PM.

ban.png
 


#10 Shaz

Shaz

    Advanced Member

  • Global Moderators
  • 4,380 posts
  • LocationAustralia
  • Primarily UsesN/A

Posted 30 May 2012 - 03:14 PM

$game_switches is only instantiated AFTER you start a game. If you have your initial code somewhere that causes it to be run on launch, $game_switches will not exist.

If you want the player to determine which battle system to use, you will either have to use a global variable that gets set from the main menu, or if you want to use $game_switches, you'll have to check it and set the battle system sometime after the new game is initialized.

#11 Zhek

Zhek

    Member

  • Members
  • 10 posts
  • Primarily UsesRMVX Ace
  • First LanguageSpanish

Posted 30 May 2012 - 04:07 PM

Bump. I thought checking for switches should've been really easy? What am I doing wrong? (Look in the above error).

Thanks for any and all help,
James


The problem is that when you check that item in the array, the array itself doesn't exist in memory yet and that's why Ruby it's telling you that's nil.

You need to do that operation somewhere else, after the code of creating the array (which is in DataManager line 87) has been executed already.





Also tagged with one or more of these keywords: rpg maker vx ace, switches, check

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users