New account registration is temporarily disabled.

[RMVX ACE] SELF VARIABLES

Posts

Pages: 1
Hi there! i was wondering if you can make my own events have self variables (like self switch) for my farm sim, and if i can is there a script to do this?
Marrend
Guardian of the Description Thread
21806
My thought is that self-variables might simply be a separate global instance of the Game_SelfSwitches class. Which probably means hacking DataManager...

module DataManager
  def self.create_game_objects
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_timer         = Game_Timer.new
    $game_message       = Game_Message.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_self_variables= Game_SelfSwitches.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
  end

  def self.make_save_contents
    contents = {}
    contents[:system]        = $game_system
    contents[:timer]         = $game_timer
    contents[:message]       = $game_message
    contents[:switches]      = $game_switches
    contents[:variables]     = $game_variables
    contents[:self_switches] = $game_self_switches
    contents[:self_variables]= $game_self_variables
    contents[:actors]        = $game_actors
    contents[:party]         = $game_party
    contents[:troop]         = $game_troop
    contents[:map]           = $game_map
    contents[:player]        = $game_player
    contents
  end

  def self.extract_save_contents(contents)
    $game_system        = contents[:system]
    $game_timer         = contents[:timer]
    $game_message       = contents[:message]
    $game_switches      = contents[:switches]
    $game_variables     = contents[:variables]
    $game_self_switches = contents[:self_switches]
    $game_self_variables= contents[:self_variables]
    $game_actors        = contents[:actors]
    $game_party         = contents[:party]
    $game_troop         = contents[:troop]
    $game_map           = contents[:map]
    $game_player        = contents[:player]
  end

...like so? I highly recommend writing a separate code-block below the Materials section in the script editor, rather than altering the base-code.

Manipulation of a self-variable would pretty much need to be done through a Script event-command, like...

key = [map_id, event_id, 'A']
# It probably could be any letter at the end, but, I wouldn't use anything other than 'A', 'B', 'C', or 'D', personally.
# I mean, self-switches go up to 'D' via the interface, so, my thought is to not mess with that too much.
$game_self_variables[key] = value

...so.
hey marrend so when i start the game with the script you showed me, an error pops up saying:

script"line 48 syntaxerror occurred
unexpected $end, expected keyword_end
end

how do i fix this?
SunflowerGames
The most beautiful user on RMN!
13323

Couldn't you self variable by resetting the variable to 0?
Marrend
Guardian of the Description Thread
21806
Oops! I did forget an "end" statement to close off DataManager's definition! In which case, I think all you have to do is put in an extra "end" statement after the function definition of self.extract_save_contents. Thus, it should look more like...

module DataManager
  def self.create_game_objects
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_timer         = Game_Timer.new
    $game_message       = Game_Message.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_self_variables= Game_SelfSwitches.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
  end

  def self.make_save_contents
    contents = {}
    contents[:system]        = $game_system
    contents[:timer]         = $game_timer
    contents[:message]       = $game_message
    contents[:switches]      = $game_switches
    contents[:variables]     = $game_variables
    contents[:self_switches] = $game_self_switches
    contents[:self_variables]= $game_self_variables
    contents[:actors]        = $game_actors
    contents[:party]         = $game_party
    contents[:troop]         = $game_troop
    contents[:map]           = $game_map
    contents[:player]        = $game_player
    contents
  end

  def self.extract_save_contents(contents)
    $game_system        = contents[:system]
    $game_timer         = contents[:timer]
    $game_message       = contents[:message]
    $game_switches      = contents[:switches]
    $game_variables     = contents[:variables]
    $game_self_switches = contents[:self_switches]
    $game_self_variables= contents[:self_variables]
    $game_actors        = contents[:actors]
    $game_party         = contents[:party]
    $game_troop         = contents[:troop]
    $game_map           = contents[:map]
    $game_player        = contents[:player]
  end
end


...so.
Hey marrend i am having a bit of difficulty using this (might be using this wrong)
when i make a 3 page event using self variable it always wants to skip to the 3 page.
eg: this is what i was doing to test it out

key = map_id, event_id, 'A'
conditional branch script:$game_self_variables = 1
show text hello
else
end
(next page)
key = map_id, event_id, 'A'
conditional branch script:$game_self_variables = 2
show text hey how are you
else
end
etcetera, so what exactly am i doing wrong here?
Marrend
Guardian of the Description Thread
21806
Hrm. I'll want to take a closer look at this to begin with, as I'm getting some very odd happenings with my brief tests. That aside, what's the condition to activate page 3 of this event?

*Edit: I had to do a bit more testing, and simply using an additional instance of Game_SelfSwitches doesn't seem like it's going to cut it. I deeply apologize for that. However, I compared what Game_SelfSwitches does against what Game_Switches does, and apply that knowledge (and referencing Game_Variables) to create a Game_SelfVariables class.

class Game_SelfVariables
  def initialize
    @data = {}
  end

  def [](key)
    @data[key] || 0
  end

  def []=(key, value)
    @data[key] = value
    on_change
  end

  def on_change
    $game_map.need_refresh = true
  end
end

I would put this under the DataManager hack, which would now look more like...

module DataManager
  def self.create_game_objects
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_timer         = Game_Timer.new
    $game_message       = Game_Message.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_self_variables= Game_SelfVariables.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
  end

  def self.make_save_contents
    contents = {}
    contents[:system]        = $game_system
    contents[:timer]         = $game_timer
    contents[:message]       = $game_message
    contents[:switches]      = $game_switches
    contents[:variables]     = $game_variables
    contents[:self_switches] = $game_self_switches
    contents[:self_variables]= $game_self_variables
    contents[:actors]        = $game_actors
    contents[:party]         = $game_party
    contents[:troop]         = $game_troop
    contents[:map]           = $game_map
    contents[:player]        = $game_player
    contents
  end

  def self.extract_save_contents(contents)
    $game_system        = contents[:system]
    $game_timer         = contents[:timer]
    $game_message       = contents[:message]
    $game_switches      = contents[:switches]
    $game_variables     = contents[:variables]
    $game_self_switches = contents[:self_switches]
    $game_self_variables= contents[:self_variables]
    $game_actors        = contents[:actors]
    $game_party         = contents[:party]
    $game_troop         = contents[:troop]
    $game_map           = contents[:map]
    $game_player        = contents[:player]
  end
end

...this. For full disclosure, my test-event was a Show Message of "Yo!", and a script call of...

test

...which calls...

def test
  map_id = $game_map.map_id
  # Returns the map ID that the player is on.
  event_id = $game_map.events[1].id
  # Returns the event ID from from the events array, specifying position #1.
  # Which happens to be 1 in this case, but, such syntax is useful if one
  # does NOT know the ID of the event to interact with.
  key = [map_id, event_id, 'A']
  
  $game_self_variables[key] = 4
  msgbox($game_self_variables[key])
end

...this function.
its similar to the other pages
key = map_id, event_id, 'A'
conditional branch script:$game_self_variables = 3
show text whats up
else
end
Marrend
Guardian of the Description Thread
21806
I was more talking about the left-hand portion of the event screen where there is a "Conditions" label, and a bunch of options. An event with multiple event-pages will place the higher priority on the page with a higher number, if possible. That's where the "Conditions" section comes into play: if a page cannot run (ie: a condition is not fulfilled), the processing will go to the previous page, and check if that page can be executed, and so on and so forth. If no page can be executed, the event will basically not show up, as there is nothing to run. Which can be a useful tactic!

However, more to the point, if your test-event has three pages, and Page 3 has no particular conditions that are required for it to run, it will run whatever's on Page 3 every single time.
oh i thought that what you were doing bypassed the conditions.....
BtW thanks marrend for your help! if i have more problems with it, i will post on the thread again.
Marrend
Guardian of the Description Thread
21806
author=dorien1010
oh i thought that what you were doing bypassed the conditions.....


Oh, dear, no. I never meant to suggest that, nor do I know how to do that. However, yeah, let me know if you have issues!
Pages: 1