How can I call an in game variable in Script editor?

Hi,


I have a script for a quest log in the script editor. For one of the quests I am making you need to kill 7 crabs and I want it to display the current variable of crabs killed in the Quest log but dont know how to call it. The line of code in this script is this:


q[😮bjectives][0]     = "Kill Crabs: " + :crabs + "/7"


This gives me an error. I decided to try something else and used :crabs[0] and gave me a "c" so I found out that it isnt giving me the variable stored in this variable just the name of it as an array. How do I get it to display the number stored inside? The variable is 0016: crabs


Thanks in advance
q[😮bjectives][0] = "Kill Crabs: " + $game_variables[16] + "/7"
Tried that but I get this error:


Script 'game_interpreter' line 1411: TypeError Occured. Can't convert Fixnum into string
do this


q[😮bjectives][0] = "Kill Crabs: " + $game_variables[16].to_s + "/7"
Also note, that won't save it, if the quests are defined in a script.  So if you kill a crab, increment the variable, do the script call then save your game and exit, if you relaunch and resume your game, it'll be back to the default value.
Thanks for your help so far. It displays now but it wont increment for some reason. Right now it isn't that big of a quest. You simply go into a house and kill 7 crabs but in the future of my game I am looking to make a quest on a larger scale that involves a quest counter. So hopefully I can get it to save the variable.
At what point do you change the variable, and at what point do you do the script call to change the quest description?


You would have to run the script call every time the variable changes.
How would you do that? Right now it is pretty basic. You talk to the woman outside the house. You agree to help her. Quest starts and shows 0/7. You go in the house and you see 7 crab sprites. Touch one and battle starts. Kill it and The variable is set to increment by 1 and turn the self switch on to remove the event. Im still pretty new to RPG maker, I just have been taking my sweet time with this game. 
You would have to run the script call every time the variable changes.



As I said though, this will not be saved with your game.  If you fix it so the value updates, then save the game and exit, when you go back in it will not show the correct number until you kill another crab.
Any way around that? 
That's MA quest log script isn't it? If so, the objectives are set and saved the minute you use reveal_objectives or anything else to get the quest to show in the log. To see this, create a quest, get it in the log, save your game, then go change it in the script. Your changes will not show up on that save game you just made, ever.


You may actually need an edit to the script to get something like that to work honestly, due to how the objectives are handled in that log.


Also, since this is about a script or script coding...


I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.


Edit: Though, you might have some luck with the following code:


Under script call:


reset_quest(x)


reveal_objective(x, 0)


where x is the id you assigned the crab quest. Put that call on every crab you kill for the quest. This will clear out the quest, and create the objectives anew, which should fix the update problem. If that doesn't work, then yes, it will probably take a script edit.
Alright. Thanks for your help, I will give it a try tomorrow
The information on the objectives is displayed using the draw_text_ex method for a reason.


That method can use message codes, so you can display your variables the same way you would do it in an evented text box.


So, try one of these:



q[😮bjectives][0] = "Kill Crabs: \V[16]/7" # Format 1
q[😮bjectives][0] = "Kill Crabs: \\V[16]/7" # Format 2
q[😮bjectives][0] = "Kill Crabs: \eV[16]/7" # Format 3


I don't think that format 1 will work, but one of the other formats should work regardless.
Sixth is correct. In a text box you can use \V[16] of 7 crabs killed!


So then in your quest log you would have "Killed crabs: \\V[16] of 7" and you would have an event that increases the variable by 1 when a crab is killed.


I disagree with the save not holding the value though. I have q[😮bjectives][1] = "Kill, Kill Count \\V[61]" in my quest


and it shows the number of kills when I save , exit and return to the game.


I'm using Modern Algebra's script.
@Sixth and Ron Thanks. I originally tried format one and it sidnt work. I will give the double backslash method a try. Thanks.
Hmmm...odd though as if you ever change the text, it will *never* update it. At least the version I have doesn't. Now maybe if you save a variable as a text code then it will handle it, just like your message boxes do. I'd be interested to see if sixth's method works myself.
Bingo Bango there's your Mango! Formay 2 works like a charm! Even sticks if you quit and restart. Thanks Sixth for the solution and thanks to everyone else for helping out as well.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-call-an-in-game-variable-in-script-editor.73904/