[RGSS3] On map load

Okay I think I know how to ask this question now.


So I load up my Custom_Class


class Custom_Class


and I'm referencing nothing, it's just my own class.


How from there would I be able to run something when the map loads?


So


class My_Class


     def initialize


          #initialize stuff


     end


     def onMapLoad


          #Do stuff


     end


end


or do I actually have to reference something.


Whenever I try to make a custom class initialize never runs unless on an event I make a SceneManager.call("")
You would need to find the appropriate method in Game_Map and put in a call to your class from there.  It depends what your custom class is all about and what you want to do with it when the map loads.  Is it a scene?  Is it something you want to be created/updated by the map?


If you only give ambiguous information, you can only receive an ambiguous response.
Iam no scripter, but maybe if you somehow know the current MAP ID than you could make:


Pseudocode:


If map_id not equals $game_variables[1] (this means a map will get loaded)


do your stuff


than control $game_variables[1] = map_id (Now the code isnt executed until the map id changes and therfor a new map


is getting loaded this frame or in the next frames.


Hope this somehow helps.
The initialize function is called when an instance of the class is created.


So $game_myclass = Game_MyClass.new <-- calls function initialize once set up.
You would need to find the appropriate method in Game_Map and put in a call to your class from there.  It depends what your custom class is all about and what you want to do with it when the map loads.  Is it a scene?  Is it something you want to be created/updated by the map?


If you only give ambiguous information, you can only receive an ambiguous response.

That's because it is, it's only a data verifyer for the character, I don't need anything specific that calls from anything.

The initialize function is called when an instance of the class is created.


So $game_myclass = Game_MyClass.new <-- calls function initialize once set up.

I think this is what I was looking for, I have to run out of the house but


class Game_Initialize


     def initialize


          $game_myclass = Game_MyClass.new


     end


end


???? That's right?
That's because it is, it's only a data verifyer for the character, I don't need anything specific that calls from anything.



That pretty much means nothing to me, sorry.  What's a data verifier?  What is it verifying?  What character?  Why do you have to do it when a map loads?


If you want your class to do something when a map is loaded, you DO need to make a specific call from somewhere.
Okay, I don't know if I'm typing it weird but I just want this code to run RIGHT when the map loads.

Code:
class Test #Run this when the map loads
  def start #Then this
    super
    initialize
  end
  
  def initialize #Then this
    @plrHunger = 100
    @plrThirst = 100
    @plrSleep = 100
    @plrPhysicalStress = 0
    @plrMentalStress = 0
    @updatetime = 0
  end
  
  def update #Then this
    if Graphics.frame_count % 60 == 0 #Then this every second
      @updatetime += 1
      if @plrHunger > 0
        @plrHunger -= 0.00347
      end
      if @plrThirst > 0
        @plrThirst -= 0.00347
      end
      if @plrSleep > 0
        @plrSleep -= 0.01
      end
      if @updatetime >= 60
        if @plrPhysicalStress > 0
          @plrPhysicalStress -= 0.025
        end
        if @plrMentalStress > 0
          @plrMentalStress -= 0.025
        end
        @updatetime = 0
        $game_variables[1] = @plrHunger
        msgbox_p(@plrHunger)
      end
    end
  end
  #Run class NPCInRange
end

class NPCInRange < Game_Map
     def placeholder
          #code for this here
     end
end
I have a feeling that what you SAY you want to happen is not really what you want to happen.


You don't run a class.  You instantiate a class once, not repeatedly (so you don't want to run that every time a map loads). You run a method within a class.  


What I see above is something I'd expect to see instantiated when the player is instantiated, and then updated on each frame update, none of which has anything to do with loading maps.  I also find it strange that you want to create a class for this, and not just add it to the Game_Player class (if it's for the player) or the Game_Event class (if it's for NPCs).


Perhaps you should explain what you're trying to achieve, and then we can help you out better.  It may be that the approach you're planning to use is entirely wrong for your requirements.
I have a feeling that what you SAY you want to happen is not really what you want to happen.


You don't run a class.  You instantiate a class once, not repeatedly (so you don't want to run that every time a map loads). You run a method within a class.  


What I see above is something I'd expect to see instantiated when the player is instantiated, and then updated on each frame update, none of which has anything to do with loading maps.  I also find it strange that you want to create a class for this, and not just add it to the Game_Player class (if it's for the player) or the Game_Event class (if it's for NPCs).


Perhaps you should explain what you're trying to achieve, and then we can help you out better.  It may be that the approach you're planning to use is entirely wrong for your requirements.

The reason I want it on its own is because it's a needs system that runs on many more things than Game_Player or Game_Event, that would be a good start now that you bring it up however I really would like it to be on its own since I need to reference scripts like Falcao Pearl ABS Liquid so that when you swing your weapon you will gain a little amount of physical exaustion as well as that you would lose some of your mental exaustion when you kill something. I have done this with game events however doing it that way causes quite a large delay on the wait system I have set up which waits for everything to be attached every in game second.


It also contacts my NPC AI script which tells itself wether an NPC is in range and checks whether the NPCs chat threshold is low (when he talks to people) in which if it is he will strike up a converstion with you.


The NPC AI was easy for myself since it was Game_Event and relied on tags which I could use to start up the script, I just didn't know about this one and still don't since I'm not 100% sure how to reference external scripts, or how to run every second (I think I found this out), or to run a script only if the player exists, the NPC one just runs whenever, I don't really care when it runs, it's NPC's I don't need to check if they're still around, shove it in an array and off they go, but for the player I need to check much much more.

Original thread: https://forums.rpgmakerweb.com/threads/rgss3-on-map-load.63298/