embooglement
Member
I'm trying to make a time reversing system similar to the one in Prince of Persia, or Braid.
basically, every frame it writes the players X and Y into a text file, and then when you press the "L" button (Q by default) it move the player to the X and Y position designated by the file, starting from the bottom.
It writes the coordinates into the file correctly, and seems to be reading them correctly as well, but when it tries to move the player it gets the error message:
"Script 'Game_Player' line 44: NoMethodError occured
undefined method `-' for #String:xxxxxxx>"
the x's at the end are random system numbers that I didn't feel like typing. The line of code it says errored is one dealing with centering the map. I didn't edit that at all.
here's the script:
then in Scene_Title, under the "command_new_game" method I put "$time_system = Time_System.new"
and in Game_Map, under the "update" method I put "$time_system.update" , underneath "$game_screen.update"
I'm not sure what the error is, any help would be greatly appreciated!
basically, every frame it writes the players X and Y into a text file, and then when you press the "L" button (Q by default) it move the player to the X and Y position designated by the file, starting from the bottom.
It writes the coordinates into the file correctly, and seems to be reading them correctly as well, but when it tries to move the player it gets the error message:
"Script 'Game_Player' line 44: NoMethodError occured
undefined method `-' for #String:xxxxxxx>"
the x's at the end are random system numbers that I didn't feel like typing. The line of code it says errored is one dealing with centering the map. I didn't edit that at all.
here's the script:
#===============================================================================
#-------------------------------------------------------------------------------
# * Class: Time_Record
#-------------------------------------------------------------------------------
#===============================================================================
class Time_System
def initialize
@file = "time.txt"
$time_file = File.open(@file, "r")
$time_file.close
end
def update
if Input.trigger?(Input::L)
read_time
else
write_time
end
end
def write_time
unless Input.trigger?(Input::L)
$time_file = File.open(@file, "a")
@player_x = $game_player.x
@player_y = $game_player.y
@player_x.to_s
@player_y.to_s
@input = @player_x
$time_file.write(@input)
$time_file.write("\n")
@input = @player_y
$time_file.write(@input)
$time_file.write("\n")
$time_file.close
end
end
def read_time
$time_file = File.open(@file, "r")
if $time_file.eof? == true
$time_file.pos=0
end
@time_array = []
@time_array = $time_file.readlines("\n")
@temp = @time_array.size
while @temp > 0
@time_x = @time_array[@temp - 1]
@time_y = @time_array[@temp - 2]
@temp = @temp - 2
reverse
end
end
def reverse
$game_temp.player_transferring = true
$game_temp.player_new_map_id = $game_map.map_id
$game_temp.player_new_x = @time_x
$game_temp.player_new_y = @time_y
end
def file_clear
$time_file = File.open(@file, "w")
$time_file.close
end
end
#-------------------------------------------------------------------------------
# * Class: Time_Record
#-------------------------------------------------------------------------------
#===============================================================================
class Time_System
def initialize
@file = "time.txt"
$time_file = File.open(@file, "r")
$time_file.close
end
def update
if Input.trigger?(Input::L)
read_time
else
write_time
end
end
def write_time
unless Input.trigger?(Input::L)
$time_file = File.open(@file, "a")
@player_x = $game_player.x
@player_y = $game_player.y
@player_x.to_s
@player_y.to_s
@input = @player_x
$time_file.write(@input)
$time_file.write("\n")
@input = @player_y
$time_file.write(@input)
$time_file.write("\n")
$time_file.close
end
end
def read_time
$time_file = File.open(@file, "r")
if $time_file.eof? == true
$time_file.pos=0
end
@time_array = []
@time_array = $time_file.readlines("\n")
@temp = @time_array.size
while @temp > 0
@time_x = @time_array[@temp - 1]
@time_y = @time_array[@temp - 2]
@temp = @temp - 2
reverse
end
end
def reverse
$game_temp.player_transferring = true
$game_temp.player_new_map_id = $game_map.map_id
$game_temp.player_new_x = @time_x
$game_temp.player_new_y = @time_y
end
def file_clear
$time_file = File.open(@file, "w")
$time_file.close
end
end
then in Scene_Title, under the "command_new_game" method I put "$time_system = Time_System.new"
and in Game_Map, under the "update" method I put "$time_system.update" , underneath "$game_screen.update"
I'm not sure what the error is, any help would be greatly appreciated!