Okay as the title says I'm having trouble applying the gsub method to what I'm trying to do.
Scene_Base (http://pastebin.com/raw.php?i=xwSvMraQ)
Biography Script [Removed Link]
When I try applying it, it works for the other two methods as they only had a string. However I guess since this is a array of items it doesn't work the same way as the others and since this is my first time applying it I'm kind of having trouble getting this to work. This is the error that is producing when I use this code.
QuoteScript 'Scene_Biography v3.0' line 86 NoMethod Error occurred.
private method 'gsub!' called for #<Array:ox32ccbe0>
You can join an array of strings into one string if that is what you need.
["a", "bc", "d"].join("") # returns the string "abcd"
gsub! and similar methods are only used in strings with either fixed strings or regular expressions as arguments.
Nope I still seem to be getting the error, but then again I probably applied it wrong.
def draw_actors_persona
info = @bio[:character_info][@actor.id]
info.gsub!(/\\[Nn]\[([0-9]+)\]/) { $game_actors[$1.to_i].name }
info.each_index {|i| contents.draw_text(8, 20+i*(20*2), 128, 24, info[i])}
info = info.join(" ")
return info
end
def draw_actors_persona
info = @bio[:character_info][@actor.id]
info.join(" ")
info.gsub!(/\\[Nn]\[([0-9]+)\]/) { $game_actors[$1.to_i].name }
info.each_index {|i| contents.draw_text(8, 20+i*(20*2), 128, 24, info[i])}
end
Try this:
def draw_actors_persona
info = @bio[:character_info][@actor.id]
info.join!(" ")
info.gsub!(/\\[Nn]\[([0-9]+)\]/) { $game_actors[$1.to_i].name }
contents.draw_text(8, 20, 128, 24, info)
end
You were still trying to loop through the indices of info like it was an array. However, you had already joined into a string. Alternatively, if you want it to stay as an array and loop through and draw each part, then you could use this:
def draw_actors_persona
info = @bio[:character_info][@actor.id]
info.each { |i| i.gsub!(/\\[Nn]\[([0-9]+)\]/) { $game_actors[$1.to_i].name } }
info.each_with_index {|i, ind| contents.draw_text(8, 20+ind*(20*2), 128, 24, i)}
end
Should be either:
or
Only methods ending with ! modify the current string. All other methods return a new string and leave the original unmodified.
I suggest this variant:
def draw_actors_persona
info = @bio[:character_info][@actor.id].join(" ")
info.each { |i| i.gsub!(/\\[Nn]\[([0-9]+)\]/) { $game_actors[$1.to_i].name } }
info.each_with_index {|i, ind| contents.draw_text(8, 20+ind*(20*2), 128, 24, i)}
end
Thank you Blizzard and ThallionDarkshine for the help. This is kind of my first time using that method so I was kind of confused, I was just lucky to get that other one to work. I guess I have more reading to do thank you.