Problem with script, Self-variable~

I've problem with system in this project lately,

I tried to make 'Self-variable' system (Same as 'self-switch', just change true/false to value), but failed.

The point is I can't remember how to control self-switches in script, so I open Game_Interpreter
and got these lines:

key = [@map_id, @original_event_id, @params[0]]
$game_self_switches[key] = (@params[1] == 0)
and I came up with this in event command 'Call Script':
key = [@map_id, @event_id, 'A']
$game_self_variables[key] = 10
I'll explain variable in here a little bit for anyone who like to know~ :3

@map_id: variable in Game_Interpreter that stores Map ID
@event_id and @original_event_id: variable in Game_Interpreter that stores ID of event that's running this command.

You will see that we can use variable in Game_Interpreter directly from event command 'Call Script', that's because all event command will process in Game_Interpreter.

However, the code above that I tried is not work~

I opened the code and found out that Game_Selfswitches saved data in Hash.
class Game_SelfSwitches

def initialize
@data = {}
end
{} or Hash.new is to create new hash.

What is Hash? It's variable that store data seperated with 'keys'. Similar theory as Array, but array will store data in 'index'.

e.g.
# Array
a = [] # [] is same as Array.new
a[0] = 'Foxkeh'
a[1] = 'is'
a[2] = 'Cute'
a[3] = 'XD'
You will see that Array stores data with its index, o, 1, 2....
# Hash
a = {}
a['one'] = 'Foxkeh'
a['y'] = 'is'
a[10] = Yeah!
Hash will store data with its 'keys', e.g. 'one' or 'y', number like 10 can use for key either.

Back to the topic, Self-variable~

I can't figure out how to control self-switches. Finally, I opened my old game in VX (well, not really old) because I controlled self-switches in that game before.

I finally got this as answer:
$game_self_switches = {[$game_map.map_id, @event_id,"A"] => false}
And it works! :)

1 comments:

Anonymous

April 18, 2008 at 9:23 AM

พยายามเข้านะครับ ผมรอเกมนี้อยู่

จาก บุคคลลึกลับ