Hello!
I was advised to seek help on this forum from RMXP script specialists.
I have a question. As you know, different RGSS scripts could be incompatable with each other. Sometimes you want to use several battle or menu systems in the game but you can't do 'cause of that.
So I've thought what of you'll make a "pocket" for each script? I.e. analogue of "Conditional Branch" command in events. Like when certain switch is turned on, script is working. If switch is turned off, so is a script.
I thought it could be done easily and tried to move code fragments from scripsts where this method is realised. But this attempt was unsuccessful, besides i don't actually get RGSS. I only get that in script should be line like "SWITCH_ID = 25" where "25" is ID of the switch. I discussed this with a person who's versed in this kind of stuff. And he proposed that "pocket" should look like this:
SWITCH_ID = 25
if ($game_switches) #If switches do exist
switch = $game_switches[SWITCH_ID]
if (switch == true)
(any possible script)
end
end
But in practice it doesn't work. It causes game shut down and error message. That person said that this method won't be workin with any complex script 'cause with any induvidual script you need use individual block modeles. I.e. you need you to look how certain is looks and going by it you need alter pocket code which makes it very difficult task.
I disagree with it. I'm sure there's a way to write universal script for a pocket in which you could place script of any complexety and bind it to working game switch.
Is it true? Does such script exists?
Help me please to solve this problem. i'm sure not only me but many developers would thank you for it.
As far as I know, I'm pretty sure that's not entirely possible the way you imagine it. The code is only read in once (saved to memory locations) before Main begins processing the game itself. It
is possible to add classes and methods during gameplay, but I don't think vice-versa.
Instead, you would have to add switches inside the class methods to simulate a similar effect.
def update
return if $game_switches[25]
# Else process code normally
end
It may be more effort than its worth.
You could write your own script that alters the functionality of said script without directly editing it. Its not as difficult as you might think.
# class of thing in your script. use the same name.
class That_Class
alias old_update update
def update
# Quit updating if the Game Switch is off
return unless $game_switches[SWITCH_ID]
# Run the renamed Update method
old_update
end
end
Just create yourself a New Script above main and below your other script.
If we had a bit more info on what specifically you were trying to accomplish with your goal instead of code suggestions, we could probably slap something out in about 10 seconds for you.