Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

disable a script to use another one instead

Hello! I was wondering whether someone knows how I can switch between two scripts. I would like to switch between the "train actor script"(which I want to use in dungeons and houses) and the "squad movement script"(I want to use it outside). I thought about creating a switch and define it in a script and the use it with a teleporting event...

It would look the following:

Test_Switch_Index = 10
if Test_Switch = true
---script---
end

in first the script and

if Test_Switch = false
---script---
end

in the second one

and then as an example:

Transfer Player:[002],(005,011)
Control Switches:[0010:Test Switch]=ON

in the event

But it does not work at all. Instead I now have two sprites on the map, 1 moves in the sqad movement way and the other one follows me with train actor!

Has anyone an idea of how I can fix this, or maybe a better idea of changing between these scripts?
 
Well, you use $game_switches[id] right? Instead of Test_Switch? If not it's not going to work by using event switches.

You could always just make it a parallel common event with a conditional branch and a couple of call scripts.

If you DO use $game_switches[id], which you probably do. Then I can't see why it does not work. How about:
Code:
if $game_switches[10]
  # call the script
else
  # call the script
end

Well, I hope it helped. I could not figure out exactly what the problem was because of the odd scripts that made no sense form the event system etc.

EDIT: Oh, and if you used the structure as shown in your post, then it has to be '==' when checking conditions. '=' will define a new value. That means that your scripts does this:

It checks if it managed to set the switch to true. It managed to do that of course, so it ran your squad movement script.
It checks then if it can set it to false. Sure it could, it runs the train actor.

This means that the train actor is the actual script that runs; or they both run at the same time.
 
Well, actuallly I did use the Test_Switch thing... I thought it works like that.
But as I see it doesn't!
But first thanks for the hint with "==", now the two sprites are gone....:thumb:
but now both of them...so my leader is the only char on the map. But I guess it's due to the fact that I cannot do the switches thing.
Because I don't know how to "call the script" in a call-script.
You're code looks so easy, but I really have no idea of how to do it.
Sorry, I just did not engage in ruby so much yet!

I can do it that not both sprites are seen, so either the train actor or the squad movement.But i cannot switch.
I'm kind of lost right now... @_@
 
You can't "disable" a script like that if it doesn't have a call function.

The train_actor script, however has this function built-in :
The line TRAIN_ACTOR_TRANSPARENT_SWITCHES_INDEX = 20 defines the index of the switch that will disable it.
 
Actually, if the scripts are SDK, you can enable and
disable them using the following calls:
Code:
SDK.enable('Script Name') 
SDK.disable('Script Name')

where Script Name is the name of the script as logged by the SDK.

If they are not sdk, then I don't see how you can do it.
 
There's no "standard" way to do that, as scripts can be triggered from anywhere.
It's quite the tricky problem, as if the original scripters didn't think of a way to easily disable it, you can't.

You should maybe post a request in the script request forum (but don't forget to post the scripts in your request)
 
try this, it isn't using call scripts but it might work.
In the script editor, insert a blank spot, put this in:
Code:
if $game_switches[10]
  #insert first script here
else
  # insert second script here
end

then just copy each script in full where it shows. also change the 10 to whatever the switch id is that you are using.
 
I have no idea why that wouldn't work. Obviously, if your getting one sprite to move one way, and the other the other way, then the code is being called, and somehow in the process the variable is being altered.

Hmm, try using an If...Else statement. If you use two If statements over an If...Else, then the variable is compared twice.

[EDIT]
Woops, I didn't see the other post's. Anywho, have you tried using the if...else structure?
 
LosAngeles;197191 said:
It gives me the following error:

View attachment 1690

The error is occurring because the $game_switches variable is still set to nil until you start or load a game. Use this code instead.

Code:
if $game_switches != nil
  if $game_switches[10]
    #insert first script here
  else
    # insert second script here
  end
end

If $game_switches == nil then it won't call the second conditional branch and either of the scripts. Of course you will have to integrate it into the code somehow. Which caterpillar and squad movement systems are you using?
 
I'm using caterpillar by fukuyama and squad movement by near fantastica.
Thanks Icarus Featherfight, now the error is gone but it still is as it was: only the party leader is on the map.
Both scripts are probably disabled now (I guess...)
 
The problem with doing it that way, As I found out, is that it only runs the if statement when you first start the game. After that, it doesn't. I think I have an idea though.... Let me test it, then I'll get back to you if it works...

EDIT:

Here is a script, it may work. I can't guarantee it yet, but let me know if you have any errors.

Code:
#=============================================================================
# ** Script Toggle Script
#  By Draycos Goldaryn
#-----------------------------------------------------------------------------
# This script will allow you to toggle between two scripts on the map.
# Just copy and paste the entire scripts where it says. The first script will
# be toggled by default. In order to toggle the second script, call the
# following in an event with call script:
#
#   $game_system.script_toggle = false
#
# Change it to true to toggle the first script.
#=============================================================================

class Game_System
  attr_accessor :script_toggle

  alias script_toggle_game_system_initialize initialize
  def initialize
    script_toggle_game_system_initialize
    @script_toggle = true
  end
end

class Script_Toggle
  def Script_Toggle.update
    if $game_system.script_toggle
      #Insert the script you want toggled by default here
    else
      #Insert the other script here
    end
  end
end

class Scene_Map
  alias script_toggle_scene_map_update update
  def update
    Script_Toggle.update
    script_toggle_scene_map_update
  end
end

Just follow the instructions in the script.....
 
The problem is, once a script has aliased his way into another, ie has been executed for the first time, you can't get it out of there.

I could be wrong, but I still think there's no easy solution, other than modifying each script.
 
The way they are used, aliases are often cumulative : they add code to a function. So it'll become quite a mess if you try to re-execute the script each time.
No, the best way is to modify the scripts in order to only update the relevant one.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top