Jump to content

rpgmakers

Member
  • Content Count

    26
  • Joined

  • Last visited

  1. rpgmakers

    Set Variable

    Yeah I tried but unfortunately it doesn't work for me. It doesn't matter anyway, it works the other way so... Thanks.
  2. rpgmakers

    pass variable from one class to another?

    You mean available to the method if set elsewhere that is not inside another method? Yeah I'm totally lost. Anyway it doesn't matter cuz I found a way around to solve my problem. Though I still believe that global variables are not "totally" global if they can't be accessed from within a method except by running that method. I mean if it's global and it changes its value throughout the program, the last value should be accessed from anywhere even if the last operation performed on the variable was inside a method or something else. I mean they shouldn't have called it global if Ruby doesn't automaticly run the method to calculate the value of the variable and retain it on the RAM somewhere for me to access at any given point in time without running that method myself. Or maybe I'm just crazy and if that's the case please tell me so I can let this go.
  3. rpgmakers

    Set Variable

    Ok, so here is what I did and it works for me: In the Game_Battler class I added: def weapon_effect_set_var_unequip(obj, effect) end under: def weapon_effect_set_var_equip(obj, effect) id, op, value = effect.value1 if op == "=" $game_variables[id] = value else $game_variables[id] = $game_variables[id].send(op, value) end msgbox_p($game_variables[id]) end And then I changed: alias :weapon_effect_set_var_unequip :weapon_effect_set_var_equip with alias :weapon_effect_set_var_unequip :weapon_effect_set_var_unequip Please let me know if you see anything wrong in this. Thanks.
  4. rpgmakers

    pass variable from one class to another?

    Yeah but doesn't that defy the whole purpose of global variable. I mean why do I have to call the method if I have a global variable wich is supposed to be known throughout the whole program. If that is the case then I don't even need a global variable if I'm calling the method. I can just do this: class A def method var = "something" end end class B a =A.new p a.method end With a local variable and that's it.
  5. rpgmakers

    pass variable from one class to another?

    You mean like this: class A attr_accessor :var def method $var = "something" end end class B a =A.new p a.method end
  6. rpgmakers

    Set Variable

    Hi Tsukihime, first of all I wanna say that this is the most useful script I've seen so far on this site. I am having a little problem though. I am trying to set the value of a variable through 2 weapons like this: Weapon1: <eff: set_var 2 = 1> Weapon2: <eff: set_var 2 = 2> So if I equip weapon1 the varible is 1. If I equip weapon2 the varible is 2. The problem is that the variable remains 2 allways, even if I equip weapon 1 again. The index of weapon2 is higher than the index of weapon1 if that has any importance. So do you have any idea what's causing this? Thanks.
  7. rpgmakers

    equip/unequip turns on/off switch [SOLVED]

    Yeah that's it. Thanks a lot.
  8. rpgmakers

    pass variable from one class to another?

    Ok first of all I want to apologize for not telling you guys that I'm no programer, I just played a bit with ruby for a couple days. And I apologize for the late response, as I was losing hope that someone would help me. All I want to know is how can I use a global variable anywhere in the program without doing this: class A attr_accessor :var end $a = A.new # I mean this: assigning a whole class to a variable $a.var = "something" class B p $a.var end I mean assigning a whole class to a single variable like I said above. Of course I tried this: class A attr_accessor :var $var = "something" end class B p $var end ... and it works! But if I do this: class A attr_accessor :var def method # notice the variable inside the method $var = "something" end end class B p $var end It doesn't work: my variable is nil. So the real question is how can I access a "global" variable that is changed inside a method in a class, from another class or from a method inside another class, because RPG Maker VX Ace has a lot of those. Now it's funny because in Ruby documentation, http://www.ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/globalvars.html it says "Global variables should be used sparingly. They are dangerous because they can be accesed from ANYWHERE." Well I can safely say that they can't be accessed from a method inside a class (proof above). Or maybe I am just an idiot, wich is probably the case, and if so, please tell me and answer this last question for me.
  9. rpgmakers

    equip/unequip turns on/off switch [SOLVED]

    I looked like a maniac but didn't find it.
  10. rpgmakers

    pass variable from one class to another?

    I thought was the way to access my variable. Like '$game_actor' is the class and 'display_var' is my global variable. I saw it was called in the same way in other scripts that work.
  11. rpgmakers

    pass variable from one class to another?

    Well, I get this error: undefined method 'display_var' for nil:NilClass So i guess my Window_Custom class doesn't recognize the variable I am trying to pass from Game_Actor
  12. rpgmakers

    pass variable from one class to another?

    So that's it?
  13. rpgmakers

    pass variable from one class to another?

    You mean I have to put 'attr_accessor' in the class in which I am calling the global variable too. I don't understand. I tried to run the code but it doesn't work.
  14. Yeah, it works. Thanks, and here is the script. I hope there is nothing wrong in it: module MY_MODULE ARRAY = [1, 2] SWITCH = 1 end #============================================================================== # ** Game_Actor #------------------------------------------------------------------------------ # This class handles actors. It is used within the Game_Actors class # ($game_actors) and is also referenced from the Game_Party class ($game_party). #============================================================================== class Game_Actor < Game_Battler #-------------------------------------------------------------------------- # * Change Equipment # slot_id: Equipment slot ID # item: Weapon/armor (remove equipment if nil) #-------------------------------------------------------------------------- alias pylon_activate_switch_with_equip_asjgf change_equip def change_equip(slot_id, item) pylon_activate_switch_with_equip_asjgf(slot_id, item) weapons = Array.new for i in MY_MODULE::ARRAY weapons << $data_weapons end if weapons.include?item $game_switches[MY_MODULE::SWITCH] = true else $game_switches[MY_MODULE::SWITCH] = false end end end
  15. Oh yeah, that was just a typing mistake. Edited
×
Top ArrowTop Arrow Highlighted