Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Bob423

[Resolved] Save and load menu editing help

Question

so i've been playing with windows and scenes, just making simple edits to the RTP scripts, and this time i edited Window_SaveFile.

 

i was trying to make it display the actor in the first slot's name, and level

so far, i have this

 

#==============================================================================
# ** Window_SaveFile
#------------------------------------------------------------------------------
# This window displays save files on the save and load screens.
#==============================================================================

class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :filename # file name
attr_reader :selected # selected
#--------------------------------------------------------------------------
# * Object Initialization
# file_index : save file index (0-3)
# filename : file name
#--------------------------------------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index % 4 * 104, 640, 104)
self.contents = Bitmap.new(width - 32, height - 32)
@file_index = file_index
@filename = "Save#{@file_index + 1}.rxdata"
@time_stamp = Time.at(0)
@file_exist = FileTest.exist?(@filename)
if @file_exist
file = File.open(@filename, "r")
@time_stamp = file.mtime
@characters = Marshal.load(file)
@frame_count = Marshal.load(file)
@game_system = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@total_sec = @frame_count / Graphics.frame_rate
file.close
end
refresh
@selected = false
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def draw_actor_name(actor, x, y)
self.contents.font.color = normal_color
self.contents.draw_text(x, y, 600, 32, actor.name, 2)
end
def refresh
self.contents.clear
# Draw file number
self.contents.font.color = normal_color
name = "File#{@file_index + 1}"
self.contents.draw_text(4, 0, 600, 32, name)
@name_width = contents.text_size(name).width
# If save file exists
if @file_exist
# Draw character
for i in 0...@characters.size
bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
cw = bitmap.rect.width / 4
ch = bitmap.rect.height / 4
src_rect = Rect.new(0, 0, cw, ch)
x = 300 - @characters.size * 32 + i * 64 - cw / 2
self.contents.blt(x, 68 - ch, bitmap, src_rect)
end
# Draw actor 1's level
actor = $game_party.actors[1]
draw_actor_name(actor, 4, 5)
# Draw play time
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(4, 25, 600, 32, time_string, 2)
# Draw timestamp
self.contents.font.color = normal_color
time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
self.contents.draw_text(4, 45, 600, 32, time_string, 2)
end
end
#--------------------------------------------------------------------------
# * Set Selected
# selected : new selected (true = selected, false = unselected)
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
if @selected
self.cursor_rect.set(0, 0, @name_width + 8, 32)
else
self.cursor_rect.empty
end
end
end

the part i edited is under *Refresh

I haven't gotten the name to work yet, but i think once that's done, the level should be easy, because i keep getting a no method error that says "undefined method: 'actors' for nil:NilClass" (it's on line 65, which says "actor = $game_party.actors[1]"

 

any suggestions? little things i can add, like a "def" thing or something?

Edited by Bob423

Share this post


Link to post
Share on other sites

23 answers to this question

Recommended Posts

  • 0

you should be usng $game_actors[ACTOR_ID]

then look under Game_Actor and you should see all of the following public instance variables:

 attr_reader   :name					 # name
 attr_reader   :character_name		   # character file name
 attr_reader   :character_hue		    # character hue
 attr_reader   :class_id				 # class ID
 attr_reader   :weapon_id			    # weapon ID
 attr_reader   :armor1_id			    # shield ID
 attr_reader   :armor2_id			    # helmet ID
 attr_reader   :armor3_id			    # body armor ID
 attr_reader   :armor4_id			    # accessory ID
 attr_reader   :level				    # level
 attr_reader   :exp					  # EXP
 attr_reader   :skills				   # skills

these store all the relevent information relating to the character so if i want to get there name i use $game_actors[ACTOR_ID].name

Share this post


Link to post
Share on other sites
  • 0

is this right? because it gives me another no method error that says that "[]" is an undefined method

actor = $game_actors[1].name
draw_actor_name(actor, 4, 5)

Share this post


Link to post
Share on other sites
  • 0

first off i completly ignored the fact that you where using the draw_actor_name method, you dont need the .name on the end as the method adds that for you, secondly Game_Actors does not exist until the game is loaded that is the reason for the errors, looking into how it stores the image in Scene_Save:

def write_save_data(file)
# Make character data for drawing save file
characters = []
for i in 0...$game_party.actors.size
 actor = $game_party.actors[i]
 characters.push([actor.character_name, actor.character_hue])
end

..................ect

end

it stores the image information into the savefile, so to add the name into that array change it to this:

[actor.character_name, actor.character_hue, actor.name]

now to use that to draw the name do something like this:

characters_name = @characters[ACTOR_ID][2]
self.contents.draw_text(x, y, width, height, character_name)

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

um...ok, so when i add that in, then what? the "def write_save_data(file)"

i get that you need to make it load the data first, and if that's how it's done, then how do i say "put the character's name here"?

 

edit OOH! i think i get it. i saw a typo and didn't know it was a typo lol

gonna try that now

 

edit: k i put that stuff in, and got a syntax error.

it seems there are either too many or too little ends.

 

here's what i have.

 

 


#==============================================================================
# ** Window_SaveFile
#------------------------------------------------------------------------------
#  This window displays save files on the save and load screens.
#==============================================================================

class Window_SaveFile < Window_Base
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader   :filename                 # file name
 attr_reader   :selected                 # selected
 #--------------------------------------------------------------------------
 # * Object Initialization
 #     file_index : save file index (0-3)
 #     filename   : file name
 #--------------------------------------------------------------------------
 def initialize(file_index, filename)
   super(0, 64 + file_index % 4 * 104, 640, 104)
   self.contents = Bitmap.new(width - 32, height - 32)
   @file_index = file_index
   @filename = "Save#{@file_index + 1}.rxdata"
   @time_stamp = Time.at(0)
   @file_exist = FileTest.exist?(@filename)
   if @file_exist
     file = File.open(@filename, "r")
     @time_stamp = file.mtime
     @characters = Marshal.load(file)
     @frame_count = Marshal.load(file)
     @game_system = Marshal.load(file)
     @game_switches = Marshal.load(file)
     @game_variables = Marshal.load(file)
     @total_sec = @frame_count / Graphics.frame_rate
     file.close
   end
   refresh
   @selected = false
 end
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------
 def write_save_data(file)
   # Make character data for drawing save file
   characters = []
   for i in 0...$game_party.actors.size
   actor = $game_party.actors[i]
   characters.push([actor.character_name, actor.character_hue, actor.name])
 end
 def refresh
   self.contents.clear
   # Draw file number
   self.contents.font.color = normal_color
   name = "File#{@file_index + 1}"
   self.contents.draw_text(4, 0, 600, 32, name)
   @name_width = contents.text_size(name).width
   # If save file exists
   if @file_exist
     # Draw character
     for i in 0...@characters.size
       bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
       cw = bitmap.rect.width / 4
       ch = bitmap.rect.height / 4
       src_rect = Rect.new(0, 0, cw, ch)
       x = 300 - @characters.size * 32 + i * 64 - cw / 2
       self.contents.blt(x, 68 - ch, bitmap, src_rect)
     end
     # Draw actor 1's level
     characters_name = @characters[1][2]
     self.contents.draw_text(4, 5, 600, 32, character_name, 2)
     # Draw play time
     hour = @total_sec / 60 / 60
     min = @total_sec / 60 % 60
     sec = @total_sec % 60
     time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
     self.contents.font.color = normal_color
     self.contents.draw_text(4, 25, 600, 32, time_string, 2)
     # Draw timestamp
     self.contents.font.color = normal_color
     time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
     self.contents.draw_text(4, 45, 600, 32, time_string, 2)
   end
 end
 #--------------------------------------------------------------------------
 # * Set Selected
 #     selected : new selected (true = selected, false = unselected)
 #--------------------------------------------------------------------------
 def selected=(selected)
   @selected = selected
   update_cursor_rect
 end
 #--------------------------------------------------------------------------
 # * Cursor Rectangle Update
 #--------------------------------------------------------------------------
 def update_cursor_rect
   if @selected
     self.cursor_rect.set(0, 0, @name_width + 8, 32)
   else
     self.cursor_rect.empty
   end
 end
end

 

 

Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

the @characters is allready being loaded thats why its easiest to add the name in there, so when you edit "def write_save_data(file)" the part that pushes the data into the array should look like so: characters.push([actor.character_name, actor.character_hue, actor.name])

 

edit:

the write_save_data(file) method is in Scene_Save, you should go edit it there :)

also : when writing the text it should be :

characters_name = @characters[ACTOR_ID][2]
self.contents.draw_text(x, y, width, height, characters_name)

sorry typo :(

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

ok, so i added it in. i deleted the def write_save_data(file) from window_savefile and stuff

 

but i got another error:

undefined local variable or method 'character_name' for #<Window)SaveFile:0x5b1e500>

on line 62, which says "self.contents.draw_text(4, 5, 600, 32, character_name)"

 

 


#==============================================================================
# ** Window_SaveFile
#------------------------------------------------------------------------------
# This window displays save files on the save and load screens.
#==============================================================================

class Window_SaveFile < Window_Base
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :filename # file name
attr_reader :selected # selected
#--------------------------------------------------------------------------
# * Object Initialization
# file_index : save file index (0-3)
# filename : file name
#--------------------------------------------------------------------------
def initialize(file_index, filename)
super(0, 64 + file_index % 4 * 104, 640, 104)
self.contents = Bitmap.new(width - 32, height - 32)
@file_index = file_index
@filename = "Save#{@file_index + 1}.rxdata"
@time_stamp = Time.at(0)
@file_exist = FileTest.exist?(@filename)
if @file_exist
file = File.open(@filename, "r")
@time_stamp = file.mtime
@characters = Marshal.load(file)
@frame_count = Marshal.load(file)
@game_system = Marshal.load(file)
@game_switches = Marshal.load(file)
@game_variables = Marshal.load(file)
@total_sec = @frame_count / Graphics.frame_rate
file.close
end
refresh
@selected = false
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
# Draw file number
self.contents.font.color = normal_color
name = "File#{@file_index + 1}"
self.contents.draw_text(4, 0, 600, 32, name)
@name_width = contents.text_size(name).width
# If save file exists
if @file_exist
# Draw character
for i in 0...@characters.size
bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
cw = bitmap.rect.width / 4
ch = bitmap.rect.height / 4
src_rect = Rect.new(0, 0, cw, ch)
x = 300 - @characters.size * 32 + i * 64 - cw / 2
self.contents.blt(x, 68 - ch, bitmap, src_rect)
end
# Draw actor 1's level
characters_name = @characters[1][2]
self.contents.draw_text(4, 5, 600, 32, character_name)
# Draw play time
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(4, 25, 600, 32, time_string, 2)
# Draw timestamp
self.contents.font.color = normal_color
time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
self.contents.draw_text(4, 45, 600, 32, time_string, 2)
end
end
#--------------------------------------------------------------------------
# * Set Selected
# selected : new selected (true = selected, false = unselected)
#--------------------------------------------------------------------------
def selected=(selected)
@selected = selected
update_cursor_rect
end
#--------------------------------------------------------------------------
# * Cursor Rectangle Update
#--------------------------------------------------------------------------
def update_cursor_rect
if @selected
self.cursor_rect.set(0, 0, @name_width + 8, 32)
else
self.cursor_rect.empty
end
end
end

 

 

 

here's the def


def write_save_data(file)
# Make character data for drawing save file
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue, actor.name])
end
[\code]

edit: i changed
[code]
characters_name = @characters[1][2]
self.contents.draw_text(4, 5, 600, 32, characters_name)

to


characters_name = @characters[1]
self.contents.draw_text(4, 5, 600, 32, characters_name.to_s, 2)

 

and it shows the name of the second character's graphic. so i get the feeling this is close.

 

edit: the 2 at the end aligns the text to the right, and so far has done just that, so i'm keeping it.

Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

the first person in the party has the id of 0, i have no idea why characters_name = @characters[1][2] did not work for you, the 1 is the id and the 2 is the location in the array of the name, starting from 0 it is 2

Share this post


Link to post
Share on other sites
  • 0

i figured out your problem while messing with that sample project from earlyer, your party only includes actor 1, which is id 0, so when you tryed to get the actors name with the id of 1 it couldnt as that actor didnt exist when the game was saved, use this to draw the text:

characters_name = @characters[0][2]
 self.contents.draw_text(4, 5, 600, 32, characters_name, 2)

and do the edit as said before to Scene_Save :)

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

ok, so that sort of works...

but i did have 2 characters in the party, so 1 should've worked

as for the second [], 2 makes it disappear, 1 shows a "0" and 0 shows the graphic name. and yes, the character has been named.

 

it might have something to do with the to_s

but if i get rid of that, i get a type error having to do with a script i have that adds shadows to the text. can't convert whatever it was into string or something

 

but i tried it in a clean project and got the same error, only it directed me to window_savefile, so that can't be it...

Share this post


Link to post
Share on other sites
  • 0

i think the problem is that your adding the code to draw the second actors name, but if he does not exist any any time its gonna throw an error as it cant get the info, this can be solved with a simple loop process like so:

for i in 0...@characters.size
characters_name = @characters[i][2]
width = self.contents.text_size(characters_name).width
x = 0 * i + width
self.contents.draw_text(x, 5, width, 32, characters_name)
end

then it will only draw the characters name if they exist, as for the x position you can alter that equation to fit your need, it multiplies it by the current i value in the loop to position each text

you can actually just add that to the loop that draws the graphic and use the same x variable to get the position correctly with the graphic

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

thanks, but i already said, i'm not drawing the second actor. i fixed that, remember?

i'll try this when i get the chance

Share this post


Link to post
Share on other sites
  • 0

ok im sort of lost, so have you successfully drawn the first actors name? that code will always draw the name of the first actor in the party, i have tested it in the project and it works fine

Share this post


Link to post
Share on other sites
  • 0

no, i meant...nevermind. i'll test the new code now.

 

i can't get it to work. i keep getting the same string error. line 63, cannot convert nil into string.

Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

what does your code look like as of now?

also try getting rid of your old save, that might have bad data in it from the previous tries

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

what is this i don't even. that worked. why does that always work?

 

thanks :D

now for the level part. how would i do that? i know i can add

self.contents.draw_text(8, -5, 600, 32, "Lv.", 2)

and then something else...

i used to be sure, but now that i know it's a little more complicated, i'm not so sure

 

this is what i have now


     characters_name = @characters[0][2]
     self.contents.draw_text(-50, -5, 600, 32, characters_name, 2)
     self.contents.draw_text(4, -5, 600, 32, "lv. 99", 2)

the loop thing wasn't needed, i just needed to start a new save file.

and the "lv. 99" is a place holder

Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

old save data, its a bitch when it comes to editing scripts, i have gotten into the habit of deleting them whenever i make changes

now to add your lvl to the sava data:

for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
characters.push([actor.character_name, actor.character_hue, actor.name])
end

so as you can see actor is your variable for getting the actors details, looking back at the public instance variables i posted earlyer, you can use any of those on the end like you did to get the name, so to get the lvl you would add it into the array of saved values, then do something like this to get it :

actors_lvl = @actors[iD][3].to_s

the 3 being that it is the third one along in the array, starting at 0 of course

 

edit:

also cutting out the to.s and drawing it as a seperate text you can make your string like so:

"lvl: #{actor_level}"

#{} gets the variable inside it and turns it into a string

Edited by diagostimo

Share this post


Link to post
Share on other sites
  • 0

oh, i get it. that's easy. thanks :D

 

edit: i think the string error had to do with the new save file thing, so i don't need that part now.

 

and it's giving me a no method error with this line

"actors_level = @actors[0][3]"

it doesn't like one of the "[]"s

 

so did i do this right?


self.contents.draw_text(4, -5, 600, 32, "lv.", 2)
actors_level = @actors[0][3]
self.contents.draw_text(0, -5, 600, 32, actors_level, 2)

 

characters.push([actor.character_name, actor.character_hue, actor.name, actor.level])

Edited by Bob423

Share this post


Link to post
Share on other sites
  • 0

draw the text like this:

actors_level = @actors[0][3]
self.contents.draw_text(0, -5, 600, 32, "lv. #{actors_level}", 2)

or

 

actors_level = @actors[0][3].to_s
self.contents.draw_text(0, -5, 600, 32, actors_level, 2)

the actors lvl needs converting to a string as it is an integer, like i said the #{} will do that within the text string

Share this post


Link to post
Share on other sites
  • 0

doesn't matter, still getting a no method error for [] on the line that says "actors_level = @actors[0][3]" not a string error.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...