Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Using this plugin, would it be possible to set a range of variables to  equal the values of another range of variables?

As in,

"Set Variables[10-20] = Variables[50-60]"??

Because I've run into a small issue in my project where during my quest generation frame work, I have a common event randomly generate the information of a quest (Item ID, Item Amount, Reward Amount, DIfficulty Level, Days to Complete, etc) in the form of 20 variables.

Those values are initially generated into my 'TempQuest Info variables", but immediatly after I need to make a Common Event to move those values into a more permanent location, such as "Quest Info Variables A", or "Quest Info Variables C"

This is what I've been using (ironically learned from a forumpost you helpfully commented on ;D)

const d = $gameVariables._data;

[d[1221], d[1222], d[1223], d[1224], d[1225], d[1226], d[1227], d[1228], d[1229], d[1230], d[1231], d[1232], d[1233], d[1234], d[1235], d[1236], d[1237], d[1238], d[1239], d[1240]]

= [d[1201], d[1202], d[1203], d[1204], d[1205], d[1206], d[1207], d[1208], d[1209], d[1210], d[1211], d[1212], d[1213], d[1214], d[1215], d[1216], d[1217], d[1218], d[1219], d[1220]];

^This scriptcall sets all the variables from my TempOrderInfo, into my OrderInfoA.

The Player has many possible quest slots so you can imagine why I'm dreading repeating this for OrderInfoB, OrderInfoC, all the way down to OrderInfoJ. T-T

(1 edit)

Hi there!

Not with this plugin. But maybe I have a better solution for you.

Add the following on any text file, and save with the extension .js, with any name you want.

/*:
@target MZ
*/

function equalsVarRange(tempVarStartId, questVarStartId, range){
    for(let i = 0; i < range; i++){
        const tempVarId = tempVarStartId + i
        const questVarId = questVarStartId + i
        $gameVariables._data[questVarId] = $gameVariables._data[tempVarId]
    }
}

After that, insert it as a plugin on your project.

So, after you set your temp quest variables, you can now use a script call:

  • equalsVarRange(tempVarStartId, questVarStartId, range)

There are 3 parameters on the script call above that you will need to replace with something. Let's take the example you showed, so I can teach you how you will replace them:

  • Set Variables[10-20] = Variables[50-60]
  • So, variables 10 to 20, are the quest variables.
  • Variables 50 to 60, are the temp variables.
  • As you can see, you have a range of 10 variables.

So, now you would replace them like that:

  • tempVarStartId = 50 (The start Id of the temp variables)
  • questVarStartId = 10 (The start Id of the quest variables)
  • range = 10

The script would need to look like this:

  • equalsVarRange(50, 10, 10)

If you don't know how to add that into your project as a plugin, you can use a script call and replace the parameters directly:

    for(let i = 0; i < range; i++){
        const tempVarId = tempVarStartId + I
        const questVarId = questVarStartId + I
        $gameVariables._data[questVarId] = $gameVariables._data[tempVarId]
    }

(+1)

Oh my gosh, such a swift reply and you made it look so effortless!!

I knew there was a way to type it using the const thing, but I just couldn't grasp anything close to that :P

I was surprised to find that there was an event command for setting a range of var to 1 variable, but not a range to another range!

Both the plugin+scriptcall, and the scriptcall by itself work flawlessly, and I'm really quite stoked to be able to continue on with the Quest frame work!

A small heads up though, it turns out the simple scriptcall wouldn't actually work, and it took some experimenting to figure out that while lowercase/uppercase typically doesn't seem to matter in these codes, It seemed both 'i' being capitalized stoped the scriptcall from working.  So switching them to lowercase did the trick!!

Again, thank you so much Hakuen, you really know your stuff and hopefully in the next week I'll be buying some others of your plugins (and possibly still this one too -that 'remove item from inventory based on variable' looks reaaaally useful for handing over the randomized quest items xD)

The I on uppercase was my bad, but you manage to solve ^^

I'm glad I could help! ^^

Happy RPG Making!