Display variable array in text/item description

Status
Not open for further replies.

rad.noire

Veteran
Veteran
Joined
Mar 19, 2017
Messages
34
Reaction score
6
First Language
English
Primarily Uses
RMVXA
hello, so i want to ask about variable array.

here is the example:
V[5] = [0, 1, 2, 3]

i want to display the second index (which mean index with value=1) in a text or item desc.
i tried to use this on show text or item description:

variable array 5 index 2 is \V[5][1]

but the result is:

variable array 5 index 2 is [0, 1, 2, 3][1]

instead, the result i want is:

variable array 5 index 2 is 1

i know that we can put array value into another variable and display said variable in example:
$game_variables[6] = $game_variables[5][1]
variable array 5 index 2 is \V[6]


but i don't want to use other variable to display said value
so how do i achieve that? any help is appreciated
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
Technically, you would need two variables. Or change how the script read escape code.

If you insist to keep the usage of game variable at a minimum.
You could instead relocate the array into another variable that technically isn't in the game variable. For example, you can use this in a script call.
Code:
$array = [0,1,2,3]
Why? Because using a game variable to store an array isn't the ideal way to do stuff. Game variables and switches are there to basically triggers an event to flip their page. Not to hold the array.

Next, you can use this
Code:
$game_variables[6] = $array[1]
However, this solution does not save $array in the saved content. So if you restart the game, the variable also resets.

If you want to use the solution above and want to include it in the save content.
You need to insert a new script.
Code:
class Game_System
  attr_writer :array
  def array; @array ||= []; end
end
And to use this, instead of $array, you use $game_system.array.

If you still insist to make \V[x][y] to work.
You gonna need to make a modification on how the escape code works. Essentially requesting a new script.
Code:
class Window_Base
  alias esc_code convert_escape_characters
  def convert_escape_characters(text)
    result = esc_code(text)
    result.gsub!(/\eV\[(\d+)\]\[(\d+)\]/i) { $game_variables[$1.to_i][$2.to_i] }
    result
  end
end
However, the thing you asked can already be done with your solution.
But you choose not to without a further explanation of why but "because I don't want to".
 

rad.noire

Veteran
Veteran
Joined
Mar 19, 2017
Messages
34
Reaction score
6
First Language
English
Primarily Uses
RMVXA
Thank you for the brief explanation regarding arrays.

But you choose not to without a further explanation of why but "because I don't want to".
i'm sorry if i'm not making myself clear. Like you said, i want to use game variables at a minimum for the sake of easier to manage.
the thing is, i want to make an item or a skill that use these variable as the way to tell it progress, in example:

- \V[1] is the variable array i want for field skill like Mining, Fishing, Farming etc. It saves Skill Level.
- \V[2] is the variable array i want for field skill experience and it values goes from 0 ~ 99
- \V[1][0] is for Mining level
- \V[2][0] is for Mining exp
- skill: Mining
- skill description: "Allow player to mine ores. Skill Level: \V[1][0] | EXP: \V[2][0] "

this is why i don't want to use my solution because i don't know how to implement that in this situation.
i'll try using your script modification instead.

edit: where do i put this code?
class Window_Base
alias esc_code convert_escape_characters
def convert_escape_characters(text)
result = esc_code(text)
result.gsub!(/\eV\[(\d+)\]\[(\d+)\]/i) { $game_variables[$1.to_i][$2.to_i] }
result
end
end
i tried to put that code on Materials but it still didn't work. do i need to put it on Window_Base?
 
Last edited:

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,592
Reaction score
6,522
First Language
Indonesian
Primarily Uses
RMVXA
a quick glance that it seems I made an error to the script. Try this instead
Code:
class Window_Base
  alias esc_code convert_escape_characters
  def convert_escape_characters(text)
    result = text.to_s.clone
    result.gsub!(/\\V\[(\d+)\]\[(\d+)\]/i) { $game_variables[$1.to_i][$2.to_i] }
    return esc_code(result)
  end
end
if that doesn't work, try this (however, you need to put this above every custom script)
Code:
class Window_Base
  def convert_escape_characters(text)
    result = text.to_s.clone
    result.gsub!(/\\/)            { "\e" }
    result.gsub!(/\e\e/)          { "\\" }
    result.gsub!(/\eV\[(\d+)\]\[(\d+)\]/i) { $game_variables[$1.to_i][$2.to_i] }
    result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
    result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
    result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
    result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
    result.gsub!(/\eG/i)          { Vocab::currency_unit }
    result
  end
end
 

rad.noire

Veteran
Veteran
Joined
Mar 19, 2017
Messages
34
Reaction score
6
First Language
English
Primarily Uses
RMVXA
a quick glance that it seems I made an error to the script. Try this instead
Code:
class Window_Base
  alias esc_code convert_escape_characters
  def convert_escape_characters(text)
    result = text.to_s.clone
    result.gsub!(/\\V\[(\d+)\]\[(\d+)\]/i) { $game_variables[$1.to_i][$2.to_i] }
    return esc_code(result)
  end
end
sweet! it works the way i want it. thank you.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,839
Reaction score
5,222
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top