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

1) Currently in playerweapon_randomly_pick_some_random_upgrades (used to pick valid choices for levelups, chests etc) we check if a weapon hasn't reached max upgrade level with the line:

global.weapon_upgrades_obtained[c] < global.weapon_data[c][pstat_UPGRADESMAX]

To give each individual upgrade a separate counter you'd need to update both of these accordingly:

  • Make global.weapon_upgrades_obtained a 2D array where the second member has PWD_LOCALDATA_MAX elements that all are initialized to 0 at the start of a run, this is done in playerweapon_initialize_run.
  • In obj_player's Alarm 0 event, the UPGRADETYPE_UPGRADEWEAPON block, now you'd change the ++ line to instead increment global.weapon_upgrades_obtained[global.confirmed_upgrades[c][upgd_WEAPONINDEX]][global.confirmed_upgrades[c][upgd_INDEX]]
  • In the playerweapons script macro section (just before playerweapon_initialize_run) add a new constant dbupgd_MAXUPGRADES, for readability I recommend putting this as 0 and incrementing all other dbupgd_ stats by 1. Then at the start of every upgrade in the database, add the desired max level there. For instance the sword's upgradedata should now start off with [[5,[pstat_ATKPOWER,1],NONE,"Whetstone"...
  • In playerweapon_randomly_pick_some_random_upgrades now finally change the second term to global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]

2) Yeah, currently triggerscripts are only used for things like the healing and money bag. I think the easiest way to implement this would be to make the actual update have no stat changes and no trigger script, and a max cap of 1 upgrades (see the answer to question 1) but the weapon's Player Shoot Script (e.g. pss_sword for the Hero Sword) checks if you have the upgrade, and if so alters the bullet's properties. The weapon script can check the variable currently_fired_weapon for the index in the player's active weapon list, and thus would check if global.weapon_upgrades_obtained[currently_fired_weapon][index_of_the_upgrade_in_the_list] > 0, for your convenience you'd probably want this upgrade to be first in the list so you don't need to count the already-confusing nested array slots.

I think for weapons using triggerscripts, you'd use them if the script does some one-off change that needs to work outside the weapon counter / PSS / stat system entirely, e.g. if the weapon creates a separate turret object rather than giving the player a weapon directly.

(1 edit)

Thank you for all your responces. I THINK I am following along so far, but the last element of Section 1 is throwing me off. What are you refering to be 'second term' in that function? Its not the argument I assume, so I'm not sure where to place that code. I've tried placing it as the second argument and setting 'include_weapons_we_have' to `global.weapon_data[c][pstat_POSSIBLEUPGRADES][d][dbupgd_MAXUPGRADES]`, but this does not work.


Edit: If by second term you meant of the initially referenced line, I changed it to the following:

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

and got the following error, just in case

___________________________________________

############################################################################################

ERROR in

action number 1

of  Step Eventobj_player

for object parent_collectibleitem:

Push :: Execution Error - Variable Index [14] out of range [2] - -5.weapon_upgrades_obtained(100135,14)

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

############################################################################################

gml_Script_playerweapon_randomly_pick_some_random_upgrades (line 97)

gml_Script_ics_exp (line 23) -               playerweapon_randomly_pick_some_random_upgrades(3,true,true,global.player_level >= 3,global.player_level >= 3,true,false)

gml_Object_parent_collectibleitem_Collision_obj_player (line 3) -               collection_script()

(+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 ^__^