[Resolved] Turn scripts on/off in-game

Started by Xyron7777777, March 14, 2010, 11:01:30 am

Previous topic - Next topic

Xyron7777777

March 14, 2010, 11:01:30 am Last Edit: March 23, 2010, 10:48:19 am by Xyron7777777
Before I started any real work on a game of my own, I decided first to create a 'Test' game. A game created entirely to prod and probe RMXP from the inside. After I got the hang of it, I started inserting small scripts (the basics) that I found randomly strewn about the internet. Some examples would include the Fullscreen prompt, a CMS, and a battle system edit to have more than 5 party members in a given fight. I havent yet tried swapping over to a full CBS, seeing as I wanted to start small.

Over time I realized that the battle system edit looked a little cheesy when the party wasnt full, and that got me thinking. Is there a way to turn a script on or off from inside the game? And I dont mean from the editor's standpoint - more like attaching the script to a variable or switch that would activate it or turn it off. Any ideas?

Kett Shee

I'm still learning RGSS myself, but it sounds like you probably have to add a command into the actual script...which would mean editing it of course.
You're all daft cunts. I love you. <3

Starrodkirby86

I suppose it might work similarly to how a person can turn on and off a feature in Tons of Add-ons and other things? Though going like that doesn't sound real nice, mmh. Definitely possible, but it's something that the script should be made with? o.o

What's osu!? It's a rhythm game. Thought I should have a signature with a working rank. ;P It's now clickable!
Still Aqua's biggest fan (Or am I?).




Valdred

at the top of the script (on the first line) put:

if $game_switches[#] == true

exchange # with the id of the switch you want to use as activator/deactivator
for example:
if $game_switches[3] == true

will use switch number 3 as activator/deactivator.

then put this:
end

at the bottom of the script(last line)

Xyron7777777

March 14, 2010, 01:15:58 pm #4 Last Edit: March 14, 2010, 01:37:40 pm by Xyron7777777
Quote from: Valdred on March 14, 2010, 12:59:31 pm
at the top of the script (on the first line) put:

if $game_switches[#] == true

exchange # with the id of the switch you want to use as activator/deactivator
for example:
if $game_switches[3] == true

will use switch number 3 as activator/deactivator.

then put this:
end

at the bottom of the script(last line)



AH! I knew it would be something simple like that! I was trying something similar to Script_name = #, but I was getting nowhere. I even tried putting a line of code 'twixt every other statement that required an 'end.' But meh, if we dont make mistakes, how will we ever learn. Thanks a ton!

**Edit** Hmm, seems to be a problem.
Spoiler: ShowHide

I placed it (copy-pasta) into the first line and replaced the # with a 33. It failed, so I tried 0033 (specifics) but still no go.

Valdred

Send me the script.

also, there must be nothing else than the text I sent you on the first and last line


Sase

Did you remember putting end on the very last line of the script?

winkio

It's happening because game_variables isn't initialized during compile. 

do this:  make a module with variables above all the other scripts, then access those variables with script calls in game to turn stuff on and off.

Valdred

I think you gotta explain that in an easier way.

Xyron7777777

@ Valdred: It wasnt any script in particular, just a question about general script interactions with RMXP. I wanted to know if it could be done easily. And yes, I remembered the 'end' at the end. Though you worried me for a second there. I thought my air-headedness had struck again  ;)

@ Arceus: Uh, ya lost me. :^_^': I'm not a very accomplished scripter yet, so you might have to put it in leyman's terms. So I need to make an entirely new script above the others and put ALL the variables in it? That sounds like it would take a long time for projects that included numerous scripts. Or am I interpreting that wrong?

winkio

First script in the editor:

module Script_Variables

 USE_SCRIPT_1 = true
 
end


you can add more variables or change the names as you need them.  The true/false values here are the default values at startup


for the script you want to turn off and on
if ($game_variables != nil && $game_variable[1]) || Script_Variables::USE_SCRIPT_1

[rest of script here]

end


once the game variables are loaded (once a file is loaded), then you can just access the game variables to change the scripts.

Xyron7777777

Ah, so only one variable is required for each script that you wish to be on a switch. You would just list them all in order under 'USE_SCRIPT_1' and set them to true for scripts active at startup, false for scripts to be turned on later. Seems easy enough.

So is the '1' inside ' $game_variable[1] ' the number of the variable that the individual script is attatched to? For example, to turn off Script_1 I would set the game's variable #0001 to '0' in game?

Jackolas