I ran into some trouble adding some debugging to equipping items onto actors within the default scripts, which has led me to some confusion on Events.
I was attempting to just go through some of the code and put in some prints to see how it functions when I ran into what appeared to be odd behavior from my perspective. Here's the code I changed in Game_Actor.
The problem is, it keeps going and going and going. It will say "New Weapon ID: 1" "Old Weapon ID: 2" "New Weapon ID: 2" "Old Weapon ID: 1" over and over and over, never stopping. I have to Alt+F4 it. I tracked this back all the way to Scene_Equip line 20: def main. It looks like it is just an infinite loop in which it refreshes the page forever. That means it constantly calls equip repeatedly (@actor.equip line 106 of Scene_Equip). That would explain the behavior I saw when trying to watch the code quoted above.
So, my question is why is it done this way? I would have thought that it would have waited for a user fired Event based on a keypress at which time it would run Game_Actor.equip. Ruby is an O-O language, and the likes of Observer Patters and Events are fairly ubiquitous (I think, at least). Is this a programming choice? Is there a reason for it? Is this a Ruby thing? Is this what I can expect throughout the default scripts?
I was attempting to just go through some of the code and put in some prints to see how it functions when I ran into what appeared to be odd behavior from my perspective. Here's the code I changed in Game_Actor.
- def equip(equip_type, id)
- case equip_type
- when 0 # Weapon
- if id == 0 or $game_party.weapon_number(id) > 0
- $game_party.gain_weapon(@weapon_id, 1)
- # TEST DEBUGGING
- print "New Weapon ID: %d" %id
- print "Old Weapon ID: %d" %@weapon_id
- # END TESTING
- @weapon_id = id
- $game_party.lose_weapon(id, 1)
- end
Expand to see the code.
The problem is, it keeps going and going and going. It will say "New Weapon ID: 1" "Old Weapon ID: 2" "New Weapon ID: 2" "Old Weapon ID: 1" over and over and over, never stopping. I have to Alt+F4 it. I tracked this back all the way to Scene_Equip line 20: def main. It looks like it is just an infinite loop in which it refreshes the page forever. That means it constantly calls equip repeatedly (@actor.equip line 106 of Scene_Equip). That would explain the behavior I saw when trying to watch the code quoted above.
So, my question is why is it done this way? I would have thought that it would have waited for a user fired Event based on a keypress at which time it would run Game_Actor.equip. Ruby is an O-O language, and the likes of Observer Patters and Events are fairly ubiquitous (I think, at least). Is this a programming choice? Is there a reason for it? Is this a Ruby thing? Is this what I can expect throughout the default scripts?

