[RMMV] CREATING A CUSTOM VARIABLE AND USING IT
Posts
Pages:
1
Hi everyone. I need some pointers on this topic.
I want to create a custom variable in RMMV and then use it.
I tried to do this through a script call and it worked... to an extent. As it is, my knowledge doesn't let me do any further modifications to said variable. Even on the same event page, the second script call that tries to tamper with it makes the software say the variable I declared two lines ago isn't declared.
I need to find a way for the maker to remember my new variable so other events can add new data to it.
I want to create a custom variable in RMMV and then use it.
I tried to do this through a script call and it worked... to an extent. As it is, my knowledge doesn't let me do any further modifications to said variable. Even on the same event page, the second script call that tries to tamper with it makes the software say the variable I declared two lines ago isn't declared.
I need to find a way for the maker to remember my new variable so other events can add new data to it.
I'm not knowledgeable in how Javascript works, but back when the game was based on Ruby, the script calls were tied to a running of the event's code. As soon as that running was completed, the variables would be forgotten... unless you defined the variables with a dollar sign instead of an @ sign. ($variable vs. @variable) The dollar sign preceding the variable made it global, and persistent in the game's memory.
If you figure out how to make a global variable in Javascript, it should last beyond one code-running. Although, you might have to look into the saving and loading process if you want it to persist in the save file. In the Ruby-based versions, you would have to put a command there for the game to specifically put that variable into the save file, and then also load it when the save file is loaded.
If you figure out how to make a global variable in Javascript, it should last beyond one code-running. Although, you might have to look into the saving and loading process if you want it to persist in the save file. In the Ruby-based versions, you would have to put a command there for the game to specifically put that variable into the save file, and then also load it when the save file is loaded.
Well, I dunno if a global variable is defined merely because a "$" character is in front of the variable's name. A number of variables that the engine uses, such as $gameActor, is defined, in some way, through the DataManager module. However, I would tend to agree, based on the description of what's going on, that a local-scope variable is being used, and whose focus is lost as soon as the "script" event-command is processed, rather than a global-scope variable.
Personally speaking, I might attach custom data to an object that already exists, such as $gamePlayer, $gameMap, or whatever. It depends on the nature of the data, but, doing so should already provide a method for the data to be saved. Like, the encounter cancel system that's in these two games attach custom variables to both $gameParty and $gameMap.
Personally speaking, I might attach custom data to an object that already exists, such as $gamePlayer, $gameMap, or whatever. It depends on the nature of the data, but, doing so should already provide a method for the data to be saved. Like, the encounter cancel system that's in these two games attach custom variables to both $gameParty and $gameMap.
Developers can totally define a global variable on the spot in Ruby/RGSS, which is part of what makes it easy to use. (They don't have to initialize or declare anything like lower-level languages.) Certain objects in RGSS, like the cited $gameActor, take their data from RPGMaker's database, which is why they have to interface through that DataManager. But if a person is just storing a piece of text, array, number, sprite, it can be made on the spot with a global variable.
I can't imagine that Javascript is as low-level as C, where you have to declare everything, but... it should be looked into.
I can't imagine that Javascript is as low-level as C, where you have to declare everything, but... it should be looked into.
Thank you for your input. I see why so many people still use VX Ace.
What I am doing is following Kazesui's tutorial on tactical movement. He wrote that some 12 years ago for RM2k3. Doing it in RMMV requires me to circumvent the variable limitation that RM2k3 did not have. (You CAN point to variables that "don't exist", but they all return 0, whereas RM2k3 returned the value you put into them).
I tried turning a game variable into an array, but then the game returns "nothing" if there are more than 100 variables in it. It doesn't crash, but the called script just does nothing like it's not there. RMMV's default game variables seem to have too many functionalities attached to them to allow them to handle the sheer volume of data that I am feeding them.
The reason I want to create a custom variable is for it to be free of many functionalities so it can handle the volume of data I am feeding it. So, I don't think attaching it to an already existing object will do the job.
If worst comes to pass, I'll switch to VX Ace if you can still have arrays and do a square root operation in your code.
What I am doing is following Kazesui's tutorial on tactical movement. He wrote that some 12 years ago for RM2k3. Doing it in RMMV requires me to circumvent the variable limitation that RM2k3 did not have. (You CAN point to variables that "don't exist", but they all return 0, whereas RM2k3 returned the value you put into them).
I tried turning a game variable into an array, but then the game returns "nothing" if there are more than 100 variables in it. It doesn't crash, but the called script just does nothing like it's not there. RMMV's default game variables seem to have too many functionalities attached to them to allow them to handle the sheer volume of data that I am feeding them.
The reason I want to create a custom variable is for it to be free of many functionalities so it can handle the volume of data I am feeding it. So, I don't think attaching it to an already existing object will do the job.
If worst comes to pass, I'll switch to VX Ace if you can still have arrays and do a square root operation in your code.
How did you refer to the game variable that you made into an array? Like, the thought in my head is that it could have some kind of call like...
...so to return the nth index of the array. This is supposing that you use the 1st index the $gameVariables array to store the data. Even so, attempting to reference the specific index of the $gameVariables array that you made into an array through Change Variables, the typical Conditional Branch, or use of the \v[1] escape character in a message box, would not likely return the results you want to see in this case.
*Edit: To be fair, I've made functions that can be accessed on a global scale in MZ. The "rest_all" function that's included in this scrpitlet collection is probably the easiest to view/access example I can provide of this kind of function. My guess is that a similar method could probably be used to make a variable on a global scale, but, allowing that variable to be saved along with the other data points would require some additional work.
MV might have a few differences from MZ, I'll grant that. Still, the underlying concept/theory should be at least somewhat transferable.
*Edit: I'm not entirely familiar with Kazeusi's tutorial on tactical movement. However, I'm now kinda wondering if using a class to perform the operations you want/need, and the ability to use that class to return the results of those operations into a more accessible place, such as the $gameVariables array, might be of interest???
$gameVariables.value(1)[n]
...so to return the nth index of the array. This is supposing that you use the 1st index the $gameVariables array to store the data. Even so, attempting to reference the specific index of the $gameVariables array that you made into an array through Change Variables, the typical Conditional Branch, or use of the \v[1] escape character in a message box, would not likely return the results you want to see in this case.
*Edit: To be fair, I've made functions that can be accessed on a global scale in MZ. The "rest_all" function that's included in this scrpitlet collection is probably the easiest to view/access example I can provide of this kind of function. My guess is that a similar method could probably be used to make a variable on a global scale, but, allowing that variable to be saved along with the other data points would require some additional work.
MV might have a few differences from MZ, I'll grant that. Still, the underlying concept/theory should be at least somewhat transferable.
*Edit: I'm not entirely familiar with Kazeusi's tutorial on tactical movement. However, I'm now kinda wondering if using a class to perform the operations you want/need, and the ability to use that class to return the results of those operations into a more accessible place, such as the $gameVariables array, might be of interest???
You guessed it right.
At this point, it is done solely through a script call that looks like
where n has to be set to the right value or else I don't get x. Since it is written code, I can even use variables as pointers. Of course, since it is not part of the maker's interface, I have to keep track of it all and know what's what.
I spent a year on Kazesui's tutorial to make heads and tails of it. It all seems much less complicated now than when I started, but I still don't have enough knowledge to write my own code.
So, the issue I am dealing with is the variable limitation. I thought I could fix that by using arrays, but the maker chokes when more than 100 variables are added to a built-in game variable. Still, the ability to make variables that are worth 100 each, that's very powerful and I foresee tons of uses from it, now that I know how to use it.
At this point, it is done solely through a script call that looks like
$gameVariables.value(1)[n] = x
I spent a year on Kazesui's tutorial to make heads and tails of it. It all seems much less complicated now than when I started, but I still don't have enough knowledge to write my own code.
So, the issue I am dealing with is the variable limitation. I thought I could fix that by using arrays, but the maker chokes when more than 100 variables are added to a built-in game variable. Still, the ability to make variables that are worth 100 each, that's very powerful and I foresee tons of uses from it, now that I know how to use it.
I chanced upon the solution to my problem in another forum. It was written 5 years ago, but darn it was it hard to find.
I'll paraphrase what the guy explained, since it could be of interest:
Since script calls are their own functions, everything you write in their prompts is self-contained and discarded when done. That means that, indeed, you have to attach your variable to something that is already global if you want it to be global.
Most people then suggest you make a modification of $gameVariables or something else in the maker, but this guy suggested something he himself qualified as outlandish: the window.
He even suggested testing it in your own browser, right here, right now by pressing F12, if your browser is Chrome or something that has this Console function and type:
So, all you have to do in RPG Maker is type in a script prompt:
and just like that, you have a global variable that can be used by any script call in the game. Just make sure that all future references to "myVar" come after the declaration, or else the game will crash.
Now, I am going to stress test this strange, yet simple method by making window.myVar an array and seeing if it can handle the data required to make Dijksra's algorithm function.
I'll paraphrase what the guy explained, since it could be of interest:
Since script calls are their own functions, everything you write in their prompts is self-contained and discarded when done. That means that, indeed, you have to attach your variable to something that is already global if you want it to be global.
Most people then suggest you make a modification of $gameVariables or something else in the maker, but this guy suggested something he himself qualified as outlandish: the window.
He even suggested testing it in your own browser, right here, right now by pressing F12, if your browser is Chrome or something that has this Console function and type:
let myVar = 5; //global scope console.log("The value is " + window.myVar); //myVar is a property of window automatically
So, all you have to do in RPG Maker is type in a script prompt:
window.myVar
Now, I am going to stress test this strange, yet simple method by making window.myVar an array and seeing if it can handle the data required to make Dijksra's algorithm function.
I'm not sure if making a variable through a browser console, or the in-game console, will work for an end user. It might depend on which platform you deploy for. A Windows deploy won't have that function, and I dunno how difficult it is to get a playable browser deploy under MV. Sure, the option to deploy for browsers is there, but, as I understand it, it's not just a matter of opening index.htm with a browser.
Though, you might be able to use a script prompt with the contents of `window.myVar = nil`, or something like that, during the opening cut-scene, or whatever, and have it equal something else later, and see what comes out.
Though, you might be able to use a script prompt with the contents of `window.myVar = nil`, or something like that, during the opening cut-scene, or whatever, and have it equal something else later, and see what comes out.
So, it works... to an extent.
Maybe I have to find ways to reduce lag or something, because it takes forever to run the algorithm when there is only 600 tiles. I didn't have the patience to wait out for the 4356 tiles I was going for (a 66x66 map).
I am at a loss. Maybe working with arrays inherently takes too much time and I really need separate variables. I know that putting (0.0)sec pauses in RM2k3 reduced lag, but that's not how it works in RMMV.
P.S. I get the sense that maybe my wording was confusing. It's not through a command console that I declare these variables, but by opening a plain script call in RMMV and typing: window.myVar in it. That's all you have to do to have a global variable that can be used outside the function in which it is created. The command console was to illustrate the principle using Javascript browsers.
Maybe I have to find ways to reduce lag or something, because it takes forever to run the algorithm when there is only 600 tiles. I didn't have the patience to wait out for the 4356 tiles I was going for (a 66x66 map).
I am at a loss. Maybe working with arrays inherently takes too much time and I really need separate variables. I know that putting (0.0)sec pauses in RM2k3 reduced lag, but that's not how it works in RMMV.
P.S. I get the sense that maybe my wording was confusing. It's not through a command console that I declare these variables, but by opening a plain script call in RMMV and typing: window.myVar in it. That's all you have to do to have a global variable that can be used outside the function in which it is created. The command console was to illustrate the principle using Javascript browsers.
Pages:
1














