Intermediate/Advanced Game Variables

Is there a way to create a conditional where we ask that a variable has a value between two other values? Example: (value1) <= variable <= (value2)
You should be able to do a script conditional:

($game_variables[#] <= value1) && ($game_variables[#] >= value2)
Deleted Post

Didn't see the second page... 
The following code:

$game_variables[26] = $game_variables[27].to_s + ":" + $game_variables[28].to_sGives me:

Script 'Game Event' line 209: ArgumentError ocurred.comparison of String with 1 failed.T.T I dunno what I'm doing wrong.

Edit: Stupid mistake from my part. I can't believe that took me almost an hour to solve... Great tutorial, btw!
I have some questions about making array in a variable;

1) Can I set variables[1] = ["In Progress", 1]?

2) If it is possible, if I would like to change either [0] or [1] in array, how can I do?

For example, talk to NPC A will change "In Progress" to "Complete". Then go talk to NPC B will change "1" to "2".

3) To print the variable in text box, can it done by \v[1][0], \v[1][1]?
1) I'm not an expert but as far as I know you can't mix different type of data in an array. (Apparently, you can!). But you can try the following:

$game_variables[1] = ["In Progress", $game_variables[x].to_s]2) If you need to change them just call it again:

$game_variables[x] += 1;$game_variables[1][0] = "Complete"$game_variables[1][1] = $game_variables[x].to_sand here is a more fancy version of it cuz I feel inspired:

$game_variables[x] += 1;if ($game_variables[x] == $game_variables[y]) #Means you reach your goal (saved in variable[y])          $game_variables[1][0] = "Complete"end$game_variables[1][1] = $game_variables[x].to_s + "/" + $game_variables[y].to_sWhat it does basically is:

1. You modify your variable.

2. You compare this variable to another one to verify it's reached its goal. If it has, then it updates to "Complete".

3. You upgrade the string containing the sum in format "nn/TT" (ex: 17/20).

3) Sorry, I'm not sure about this one 🙁 But you can always use an auxiliar variable for showing text:

$game_variables[z] = $game_variables[1][0] + ", " + $game_variables[1][1]and then print \v[z] 🙂

Hope it helped. Someone correct me if I'm wrong please.
1) I'm not an expert but as far as I know you can't mix different type of data in one array. But you can try the following:

$game_variables[1] = ["In Progress", $game_variables[x].to_s]2) If you need to change them just call it again:
Code:
$game_variables[x] += 1;$game_variables[1][0] = "Complete"$game_variables[1][1] = $game_variables[x].to_s
and here is a more fancy version of it cuz I feel inspired:
Code:
$game_variables[x] += 1;if ($game_variables[x] == $game_variables[y]) #Means you reach your goal (saved in variable[y])		  $game_variables[1][0] = "Complete"end$game_variables[1][1] = $game_variables[x].to_s + "/" + $game_variables[y].to_s
What it does basically is:1. You modify your variable.

2. You compare this variable to another one to verify it's reached its goal. If it has, then it updates to "Complete".

3. You upgrade the string containing the sum in format "nn/TT" (ex: 17/20).

3) Sorry, I'm not sure about this one 🙁 But you can always use an auxiliar variable for showing text:

$game_variables[z] = $game_variables[1][0] + ", " + $game_variables[1][1]and then print \v[z] 🙂 Hope it helped. Someone correct me if I'm wrong please.
Wow! This is very advance scripting thing for me indeed! Frankly speaking, the reason of my question is I'm making a quest system using events and variableS for tracking progress. Quests may contain no. of monsters killed or item pick up and status of a quest (e.g. Quest Status: In Progress #\v[1][0], Zomebie 4/5 #\v[1][1] defeated). However; if I use one variable for each aspect, there gonna be lots of variables and it may be bit hard to control. I'll try what you have suggested. Thanks!!
I figured 😛

I suggest you use a variable for each quest, for example:

For the "Slain the Zombiez!" quest you will keep track in:

$game_variables[100] = [0, 5] where 100 is the variable ID referring to the "Slain the Zombiez!" quest. This contains information of both: the number of current slain monsters and number of required monsters.

And no need to use the extra variable for "Progress/Completed". You will get that just by comparing the two integers in the array:

if $game_variables[100][0] >= $game_variables[100][1]          string = "Completed!"else string = "In Progress"endWish I could make it clearer >o<
Kyuukon pretty much got everything perfectly. You can't mix different types of data in an array. To do that you'd need to use a hash instead, but I have little experience in that department.

A few things. I'll start with what Kyuukon already has in place:

$game_variables[x] += 1;
if ($game_variables[x] == $game_variables[y]) #Means you reach your goal (saved in variable[y])
         $game_variables[1][0] = "Complete"
end
$game_variables[1][1] = $game_variables[x].to_s + "/" + $game_variables[y].to_s
We can shortform the IF to something like this:

$game_variables[x] == $game_variables[y] ? $game_variables[1][0] = "Complete" : 0

That's a ternary operator where the stuff before the ? is checked. If it's true, then the next thing happens ($game_variables[1][0] = "Complete") otherwise the thing to the right of the colon ( : ) happens. ( 0, basically nothing as far as I can tell)

if you've already converted the integer into a string ( $game_variables[x].to_s ) You'll have to revert it back if you want to modify it. Say you wanted to just up the value instead of using variable x. If it were still an integer then you can simply do this:

$game_variables[1][1] += 1

but it's a string, so you have to revert it first.
$game_variables[1][1] = ($game_variables[1][1].to_i + 1).to_s

note: on the other hand, I tested and it seems you can mix strings and integers in the array, but it's probably better to be safe than sorry.

Of course there's a better way I think. Instead of doing all this mumbo jumbo, you should use a single integer for each quest as opposed to two different data types.

0 means quest hasn't been started.

Any positive integer means its on the way

then set it to -1 when the quest is complete.

So to check if it's in progress it's just a matter of checking to see if the value is 1 or more. Same thing vice versa to check if it's complete.

Some more advanced uses include using a 2D array, which is basically arrays within an array. Say you wanted a quest to have multiple values and not just a quest tracker from start to finish.

Quest 3:

1 tracker

2 number of caves excavated

3 number of relics found

So you need to set an array for Quest 3, inside of the Quest array (variable 1, which is already an array)

$game_variables[1][3] = []  (sets it as an array)

Now you've got a whole array inside quest 3's entry! (Remember that [1] is the Variable, [3] is the entry in that first array, the third [ ] is the entry in the second array)

$game_variables[1][3][0] = tracker

$game_variables[1][3][1] = caves excavated

$game_variables[1][3][2] = relics found

Yes you can put an array within an array within an array, and so on, but it gets messy and confusing there so it's best to stick with 2D to start.

If you wanna see other possibilities, see if this gets the juices flowing:

$game_variables[20][this.id][0] = health

$game_variables[20][this.id][1] = defense

$game_variables[20][this.id][2] = attack

$game_variables[20][this.id][3] = [3, 7, rand(10)] (drops)

where this.id is the events ID.

for drops, you can loop through that array and add the item via:

$game_party.gain_item($data_items[$game_variables[20][this.id][3][0]], 1)  (item ID 3)

$game_party.gain_item($data_weapons[$game_variables[20][this.id][3][1]], 1) (weapon ID 7)

$game_party.gain_item($data_armors[$game_variables[20][this.id][3][2]], 1) (random armor ID 0 through 9)

Well, I rambled on long enough.
@Kyuukon and @seita

Thanks for your kind help and idea shared with me!! Because I tried to look for a quest log scripf but it is not very easy to set it up (or only me perhaps..)

@Kyuukon - I don't really have an idea about your example when you compare variable[100][0] >= [1] then you set string = completed. How can I print the string in a text box?

@seita - I pretty much understand your point now but just wondering if I can only use one variable to keep every data for a quest (integer, string). My quest system is very simple by creating a quest log item and call common event when used. The common event contains 2 text boxes look like this;

Quest No.: xxx

NPC: (name, location)

Quest Status: In Progress of Complete #print out by \v[1][0]

Mission: Kill \v[1][1] of 10 Zombies and return to the NPC

Quest Reward: xxxx

Anyway, I will follow what you suggested me for a safe bet. Could you explain a little bit about your last example about variables[20]? What is the situation that fits your example?

Thanks a lot!!
@Murd: Every time you need to print something, create an auxiliar variable:

$game_variables[20] = string #where 'string' is the script local variable you put all the info you want to show.

Then \V[20]

Look, here is the function I use for the clock system in my game:

HH = $game_variables[27].to_s #Hoursif($game_variables[28] < 10)   MM = "0" + $game_variables[28].to_s #Minuteselse   MM = $game_variables[28].to_s #Minutesend$game_variables[26] = HH + ":" + MMI run this every time the player steps near the clock and then I proceed to show the variable with ID 26, which displays in format HH:MM (ex: 8:05). All in a common event.

Btw, if you're looking for a quest journal script I recommend this: http://rmrk.net/index.php?topic=45127.0 🙂 (MA scripts are highly customizable and very well coded but require you to actually read and learn). But maybe give it a try?
@murd

I'm out right now replying on the phone so this might be short. Variable 20 is just an example for what you can do with 2D arrays, nothing to do with your situation. For what you want to do you can just do this:

assuming: Var1 is your quest array, and quest 3 is already started.

$game_variables[1][3] = [] (set quest 3 its own array only once, preferably when it starts)

$game_variables[1][3][0] is your quest tracker. Set to -1 if complete.

$game_variables[1][3][1] is number of zombies killed.

var 10 and 11 are temporary variables, only used for printing to message box.

$game_variables[1][3][0] >= 1 ? $game_variables[10] = "In Progress" : $game_variables[10] = "Complete"

$game_variables[11] = $game_variables[1][3][1]

now use var 10 and 11 to show progress and zombies killed in the message box.
@Kyuukon - Ohh! Thank you for your explaination about your sample of clock system. I will see whether I can adapt it to my project in some ways. For the script you recommended, I tried to check it out once but there are many points that are not completely clear to me. So I decided to create a simple quest system for my own project. Anyway I'll give it a try!

@seita - I must be stupid enough but just to make sure I completely understand your point.

Var[1 #No. of var for questing][3 #No.of quest (can be any quest no. here?)][0 #No problem now]. Am I correct?
That's correct sir~
That's correct sir~
Ok thank you again seita!!
I want to ask something, if I put string on a variable, a space would be like this (" "), right?
Then, how about enter? Can we put it into variable too?
I want to ask if Arrays can read and display icons correctly by using message characters( I think it is called)

@te1 = \\I[80]
@te2 = \\I[79]
Like this. @arraytest = [@te1, @te2]

I can only get my array to display the variable's value ("\\I[80]", "\\I[79]") like strings. Is it possible to make the array understand the useage of
message characters and to display the icon provided by the value from my variables?
Not really, no. The processing of escape characters is part of Window_Message. What you CAN do is set the array elements to strings like "\\i[80]" and then do $game_message.add(@te1); and it'll show the icon.
I'm looking for the script command to display the current value of a variable
Assuming you mean the variables you can change through the maker's interface, that is $game_variables[n] (n being the number to identify that specific variable). Because if $game_variables[1] = 25, then $game_variables[1] + 20 is the same as 25 + 20.

If you mean actually displaying a variable on the screen, it's not really a variable-related question. However, you generally want to use
draw_text(x, y, width, height, text) which is found in Window_Base, meaning you'd have to make a window (or use a pre-existing one).
Drawing text is done for the scripts. An easy way (if it's what was desired) is to just use a text box and display the variable with \V[n]

Original thread: https://forums.rpgmakerweb.com/threads/intermediate-advanced-game-variables.16541/