Draycos Goldaryn
Member
Ok, Here is what i am trying to do. Using the RGSS Web Kit, and some remote php scripts, I am trying to edit the scene save and load screens to save each object's data to a remote mySQL database. I think I know how to save the data. using obj.inspect, I can convert each object into a string... ie:
I can then split the string and store the variables in specific columns in the mySQL. I believe I can then retrieve them and put them back together again into the original string, but how would I convert the string and overwrite the object with it's data, including the unique identifier (ie: #<Game_System:0x7ffc000)? Or is this not possible?
Code:
$gs_string = $game_system.inspect
p $gs_string #=> "#<Game_System:0x7ffc000 @opacity=255, @face_frame_width=100, @font="Arial", @face_graphic_justification=6, @axial_movement=false, @slave_windows={}, @name="", @train_actor=-1, @window_height=128, @wait=0, @magic_number=5944682, @message_position=2, @windowskin="", @show_pause=false, @shadow_color=(0.000000, 0.000000, 0.000000, 100.000000), @skip_mode=1, @timer_working=false, @animation_pause=80, @name_window=false, @face_graphic="", @default_movement=true, @map_interpreter=#<Interpreter:0x7ffbf88 @button_input_variable_id=0, @list=nil, @main=true, @parameters=[], @move_route_waiting=false, @index=4, @depth=0, @branch={}, @wait_count=0, @message_waiting=false, @child_interpreter=nil, @event_id=1, @loop_count=1, @map_id=1>, @shortcuts={}, @sound_effect="", @message_event=-1, @text_mode=0, @encounter_disabled=false, @resting_animation_pause=80, @text_justification=6, @shadowed_text=false, @ums_mode=0, @timer=0, @animated_faces=false, @comic_style=0, @window_justification=1, @save_count=1, @used_codes=["\\v", "\\n", "\\c", "\\g", "\\skip", "\\m", "\\height", "\\width", "\\jr", "\\jc", "\\jl", "\\face", "\\fl", "\\fr", "\\b", "\\i", "\\s", "\\e", "\\t1", "\\t2", "\\th", "\\nm", "\\font", "\\p", "\\w", "\\ws", "\\oa", "\\oi", "\\os", "\\ow", "\\tl", "\\tr", "\\tc", "\\ignr", "\\shk", "\\slv", "\\ind", "\\inc"], @text_shake=0, @choice_position=0, @write_speed=0, @menu_disabled=false, @back_opacity=160, @resting_face="", @font_color=nil, @face_graphic_position=1, @numpad_movement=false, @battle_interpreter=#<Interpreter:0x7ffbf70 @button_input_variable_id=0, @main=false, @move_route_waiting=false, @depth=0, @branch={}, @wait_count=0, @message_waiting=false, @child_interpreter=nil, @event_id=0, @map_id=0>, @indy_windows={}, @comic_enabled=false, @window_width=480, @message_frame=0, @window_image=nil, @shake=0, @choice_justification=4, @text_skip=true, @save_disabled=false>"
I can then split the string and store the variables in specific columns in the mySQL. I believe I can then retrieve them and put them back together again into the original string, but how would I convert the string and overwrite the object with it's data, including the unique identifier (ie: #<Game_System:0x7ffc000)? Or is this not possible?
Ok, I just found out, that hex number is actually a memory address where the object is stored, and it varies between games, even when opening saved games. The object id (found with $game_system.object_id and is a FIXNUM) will also change when loading a saved game from the id that it was when saved, so that is out as well. I suppose the next question would actually be, is there a better way to reload the data than manually editing each class instance variable from the string? for instance. I was thinking of creating the new class using (for example) $game_system = Game_System.new, then splitting the downloaded string and changing each @variable in the class to the value in the string if different. I would have to include an id of my own that is unique to each user's save to organize the data.
Is there a way to store a ruby object keeping the object intact without using marshal.dump, or can marshal.dump be used to store to mySQL? and marshal.load to load from mySQL?