On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(+1)

Second term as in "global.weapon_data[c][pstat_UPGRADESMAX]".

Hmm, judging by the message everything wasn't set up as expected (the upgrades_obtained array is too short), it should be a two-dimensional array that's got as many slots on the first axis as the number of weapons the player can obtain, and the second axis should have PWD_LOCALDATA_MAX elements (now I'm realizing that's not actually correct, you want this number to be the max number of different upgrade choices any weapon can have - we're addressing by upgrade index and not by stat - but so far none of them has 12 upgrade paths so it should be fine).

But either way, global.weapon_upgrades_obtained should be at least a 6-by-12 element array, but it's only 2 elements along one axis, so something's weird there. The first step would be to print its contents with show_debug_message(global.weapon_upgrades_obtained) at the start of the function and see what's actually in it when the game crashes. (Note that it's not enough to just set array[5][11] to 0 when initializing it, that'll give you a 6 element array which contains a 12-element array in the 6th slot and the number 0 in the prior five slots - 2D arrays are just arrays of 1D arrays so if you want the inner arrays to have the same length you need to manually put one in every slot of the outer array)

Oh yeah, and another issue, you're checking global.weapon_upgrades_obtained[c], but you should check global.weapon_upgrades_obtained[c][d] because upgrade level is per-upgrade now instead of shared for the entire weapon. (You'll need to move this check into the loop over array_length(ups) as well)

I apologize for the very long delay in reply, but I ended up frustrated and giving up on the project due to not being able to get it working. Trying it again now, I believe I managed to create the 2D array properly wit the following:


global.weapon_upgrades_obtained = array_create(WID_MAX,0) //Number of upgrades for each weapon in the game

//global.weapon_upgrades_obtained = [array_create(WID_MAX,0),array_create(PWD_LOCALDATA_MAX,0)] //Number of upgrades for each weapon in the game

global.passive_upgrades_obtained = array_create(PID_EX_MAX,0) //Number of upgrades for each passive in the game

//Properly Initialize Var

for(var i = 0; i < array_length(global.weapon_upgrades_obtained); i++) {

    global.weapon_upgrades_obtained[i] = array_create(PWD_LOCALDATA_MAX);

}



But now the line that is:

if((global.weapon_upgrades_obtained[c][d] < global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]) || allow_surpassing_max_level){ //Can we upgrade it further?


throws me an error about local variable 'd' not being found, which makes sense since its not initially until the loop starts beneath that line of code.

(+1)

It's been so long I've completely lost my original train of thought (happy 100-day anniversary!) but just looking at the last line in my last post, I think there's a clue here:

Oh yeah, and another issue, you're checking global.weapon_upgrades_obtained[c], but you should check global.weapon_upgrades_obtained[c][d] because upgrade level is per-upgrade now instead of shared for the entire weapon. (You'll need to move this check into the loop over array_length(ups) as well)

I.e. if the loop fails because you don't set d, it's probably actually a symptom that you still only loop over one variable (you need to loop over all weapons, and then inside that loop, have another loop that loops over all the upgrades defined for that weapon).


(In case you're wondering about the names, I always name my first loop counter c because then I get to write "c++" for the increment statement and I find that funny. And then for subsequent inner loops I use d, e, f and so on because I ran out of programming languages and it's easier just cycling through all letters)

(+1)

I greatly apologize for that delay: and interesting tidbit, actually. I have only used 'i' for local variables or a relavant title because of some mental carry over from RPG Maker.


That aside: You're a god. I just moved the code to be:

for(var c = 0; c < WID_MAX; c++){

if(playerweapon_has(c)){

if(include_weapons_we_have){

var ups = global.weapon_data[c][pstat_POSSIBLEUPGRADES];

for(var d = 0; d < array_length(ups); d++){

if((global.weapon_upgrades_obtained[c][d]  < global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]) || allow_surpassing_max_level){ //Can we upgrade it further?

At the top of that function and it seems to be working perfectly. Now I'm just going to add some text to show the current 'level' of that upgrade for visual clarity. Thank you so very much for helping me out and your patience.

No problem! Glad you finally got it working ^__^