RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Script from within a Move Action (solved)

0 Members and 1 Guest are viewing this topic.

*
Rep: +0/-0Level 66
RMRK Junior
Howdy!

How does calling a script from within a move action or the autonomous movement differ from calling a script directly in said event?

Namely, I have a custom function pushed into the Game_Interpreter class in one of my scripts so I can call these functions from within events.

Now, if I call those functions from within a conditional action, or a normal script action, it works fine. But when I try to use it within a move action's script, it gives me a NoMethodError occurred error message. This leads me to believe that movement actions somehow don't have access to the Game_Interpreter functions, or... something.

In case it's necessary, here's the functions I've added to the Game_Interpreter:
Code: [Select]
class Game_Interpreter
    def set_self_switch (mapID, eventID, selfSwitch, trueOrFalse)
        key = [mapID, eventID, selfSwitch]
        $game_self_switches[key] = trueOrFalse
        $game_map.need_refresh = true
    end
   
    def get_self_switch (mapID, eventID, selfSwitch)
      key = [mapID, eventID, selfSwitch]
      result = false
      result = $game_self_switches[key]
      return result
    end
end

And indeed, it's an altered version of iKuro's SelfSwitchController. And indeed, the get_self_switch isn't optimal, but it's not about that right now.

Regardless, how does calling a script from within a movement action differ from calling a script from within the event directly?


-Mikau
« Last Edit: September 13, 2011, 11:26:10 AM by MikauSchekzen »

*
Rep:
Level 82
I'm not sure if I'm correct, but I'll give it a go anyway. Someone else who does know can come across to correct me if need be.

This is the idea that I get from working with modern algebra's Path Finding script once.

Game_Interpreter is used as part of the classes Game_Map, Game_Event and Game_Troop. Thus, any call to a method using any object made up of one of these classes (that is, a Game_Map object, a Game_Event object or a Game_Troop object) will be making a check to Game_Interpreter for any methods that don't directly exist in these 3 classes.

However, the "Set Move Route" is part of the Game_Character class which does not make any reference to Game_Interpreter at all and so methods that are called within the "Set Move Route" script call will throw up a NoMethodError - as far as Game_Character knows, Game_Interpreter doesn't even exist.

Simply put, it has something to do with where and when the Game_Interpreter class can be seen/is used. By default, this is only seen by Game_Event, Game_Map and Game_Troop. If you want to make use of these methods in a script call through "Set Move Route" you'll have to make them visible to the Game_Character class - the simplest way would probably be to make a copy of the two methods and paste them into the Game_Character class.

Also, I know it's not the focus but just straight away I'm not sure why you make two assignments to the same variable in the get_self_switch method, one after the other. It's pretty pointless as the assignment will be made twice regardless of if the actual value would be the same or not which costs a small amount of additional processing time. It isn't going to run checks to see whether or not to update the contents of the variable because that'd cost more processing time than just simply assigning it again (probably already know that, but it's there anyway).
(Why do I always feel like it's the end of the world and I'm the last man standing?)

*
Rep: +0/-0Level 66
RMRK Junior
Many thanks! This will help me understand the hierarchy better.

For now, I just did as you said: copy the methods to the Game_Character class. Or rather, the Game_Event class. That seemed to work. I did that because when I called for the class' name within a move route, it returned Game_Event.

Regardless, it works, so I'm happy, even though it isn't very clean code :[


As for the double assignment, I was originally planning to make the second assignment only if it could find said switch, but I didn't know how, exactly. Or something. I'll look into it.


-Mikau

*
Rep:
Level 82
Quote
As for the double assignment, I was originally planning to make the second assignment only if it could find said switch, but I didn't know how, exactly. Or something. I'll look into it.

You mean to check if the event for the desired self switch actually exists?

Post: I did some testing with a bit of code to throw up an error if you tried asking for a self switch for an event that didn't exist on the map. However, I found that in this case, the return is simply false and causes no apparent issues.

The reason it returns false can be found in the Class Game_SelfSwitches. For all cases where the desired Key is true, the return is true. If it is anything else (be it false, 9, "random string" etc) it will always return false. If you wanted to do something different with how this handled, you would need to overwrite this method in this class:

Code: [Select]
  def [](key)
    return @data[key] == true ? true : false
  end

This would drastically change how the self switches are checked by the game system so it would be worth making sure it isn't going to cause too many issues if you did change it - there might be a lot of work involved but this I'm not about to find out.
(Why do I always feel like it's the end of the world and I'm the last man standing?)