GMS 2 [SOLVED] Greater than 16 Arguments

S

Spencer S

Guest
I have an object called obj_inventory, an object called obj_pickup and a script called scr_add_item. I need to send over 50 arguments to the script from obj_pickup, but I can't. So I have written the following in each object and script:

obj_inventory:
Code:
globalvar playerInventory, playerInventoryWidth;
playerInventoryWidth = 53; //Changeable based on the stats needed
playerInventory = ds_grid_create(playerInventoryWidth, 1); // create the inventory
obj_pickup:
Code:
/// @description Create Item Stats
itemStatGrid = ds_grid_create(54, 1);

objectID = id;
gridToAddToFromItem = undefined; // Grid we'll be adding the item to
itemName = undefined; // The item name
itemDescription = undefined; // The item description
itemSprite = undefined; // The sprite the item will inherit
itemAmount = undefined; // The amount of the item we'll be picking up
itemScript = undefined; // The script the item will use (if any)
itemArmor = undefined; // The armor value of the item in numbers, before turned into % reduction
itemHyperHP = undefined; // The HyperHP value of the item
itemHyperArmor = undefined; // The HyperArmor value of the item, before turned into % reduction
itemStamina = undefined; // The Stamina value of the item
itemStaminaRegen = undefined; // The Stamina Regeneration value of the item, before turned into % reduction
itemMana = undefined; // The Mana value of the item
itemManaRegen = undefined; // The Mana Regeneration value of the item, before turned into % reduction
itemStrengthBonus = undefined; // The Strength value of the item
itemIntellectBonus = undefined; // The Intellect value of the item
itemDexterityBonus = undefined; // The Dexterity value of the item
itemToughnessBonus = undefined; // The Toughness value of the item
itemWisdomBonus = undefined; // The Wisdom value of the item
itemProficiencyBonus = undefined; // The Proficiency value of the item
itemLuckBonus = undefined; // The Luck value of the item
itemAttackSpeedBonus = undefined; // The Attack Speed Bonus value of the item in numbers, before turned into % reduction
itemCastSpeedBonus = undefined; // The Cast Speed Bonus value of the item in numbers, before turned into % reduction
itemWeaponMagicDamage = undefined; // The Magic Damage value of the item (a staff with a magic damage value of 20 will add 20 damage onto whatever spell is cast)
itemWeaponPhysicalDamage = undefined; // The Physical Damage value of the item (a sword with a physical damage value of 20 will deal 20 damage before other multipliers)
itemWeaponPoisonDamage = undefined; // The Poison Damage value of the item (a dagger with a poison damage value of 20 will deal 20 poison damage before other multipliers)
itemWeaponToxicDamage = undefined; // The Toxic Damage value of the item (a dagger with a toxic damage value of 30 will deal 30 poison damage before other multipliers)
itemWeaponBaneDamage = undefined; // The Bane Damage value of the item (a dagger with a bane damage value of 40 will deal 40 bane damage before other multipliers)
itemWeaponFireDamage = undefined; // The Fire Damage value of the item (a dagger with a fire damage value of 20 will deal 20 fire damage before other multipliers)
itemWeaponFrostDamage = undefined; // The Frost Damage value of the item (a dagger with a frost damage value of 20 will deal 20 frost damage before other multipliers)
itemWeaponElectricDamage = undefined; // The Electric Damage value of the item (a dagger with a electric damage value of 20 will deal 20 electric damage before other multipliers)
itemWeaponLightDamage = undefined; // The Light Damage value of the item (a dagger with a light damage value of 20 will deal 20 light damage before other multipliers)
itemWeaponDarkDamage = undefined; // The Dark Damage value of the item (a dagger with a dark damage value of 20 will deal 20 dark damage before other multipliers)
itemTrueMagicDamage = undefined; // The True Magic Damage value of the item
itemTruePhysicalDamage = undefined; // The True Physical Damage value of the item
itemPoisonDPSBonus = undefined; // The Poison Damage Bonus value of the item, before turned into % value
itemPoisonResist = undefined; // The poison Resist value of the item, before turned into % value
itemToxicDPSBonus = undefined; // The Toxic Damage Bonus value of the item, before turned into % value
itemToxicResist = undefined; // The Toxic Resist value of the tiem, before turned into % value
itemBaneDPSBonus = undefined; // The Bane Damage Bonus value of the item, before turned into % value
itemBaneResist = undefined; // The Bane Resist value of the item, before turned into % value
itemPhysicalDamageBonus = undefined; // The Physical Damage Bonus value of the item, before turned into % value
itemPhysicalResist = undefined; // The Physical Resist value of the item, before turned into % value
itemFireDamageBonus = undefined; // Fire Damage Bonus value of the item, before turned into % value
itemFireResist = undefined; // The Fire Resist value of the item, before turned into % value
itemFrostDamageBonus = undefined; // The Frost Damage Bonus value of the item, before turned into % value
itemFrostResist = undefined; // The Frost Resist value of the item, before turned into % value
itemMagicDamageBonus = undefined; // The Magic Damage Bonus value of the item, before turned into % value
itemMagicResist = undefined; // The Magic Resist value of the item, before turned into % value
itemElectricDamageBonus = undefined; // The Electric Damage Bonus value of the item, before turned into % value
itemElectricResist = undefined; // The Electric Resist value of the item, before turned into % value
itemLightDamageBonus = undefined; // The Light Damage Bonus value of the item, before turned into % value
itemLightResist = undefined; // The Light Resist value of the item, before turned into % value
itemDarkDamageBonus = undefined; // The Dark Damage Bonus value of the item, before turned into % value
itemDarkResist = undefined; // The Dark Resist value of the item, before turned into % value


ds_grid_set(itemStatGrid, 0, 0, gridToAddToFromItem)
ds_grid_set(itemStatGrid, 1, 0, itemName)
ds_grid_set(itemStatGrid, 2, 0, itemDescription)
ds_grid_set(itemStatGrid, 3, 0, itemSprite)
ds_grid_set(itemStatGrid, 4, 0, itemAmount)
ds_grid_set(itemStatGrid, 5, 0, itemScript)
ds_grid_set(itemStatGrid, 6, 0, itemArmor)
ds_grid_set(itemStatGrid, 7, 0, itemHyperHP)
ds_grid_set(itemStatGrid, 8, 0, itemHyperArmor)
ds_grid_set(itemStatGrid, 9, 0, itemStamina)
ds_grid_set(itemStatGrid, 10, 0, itemStaminaRegen)
ds_grid_set(itemStatGrid, 11, 0, itemMana)
ds_grid_set(itemStatGrid, 12, 0, itemManaRegen)
ds_grid_set(itemStatGrid, 13, 0, itemStrengthBonus)
ds_grid_set(itemStatGrid, 14, 0, itemIntellectBonus)
ds_grid_set(itemStatGrid, 15, 0, itemDexterityBonus)
ds_grid_set(itemStatGrid, 16, 0, itemToughnessBonus)
ds_grid_set(itemStatGrid, 17, 0, itemWisdomBonus)
ds_grid_set(itemStatGrid, 18, 0, itemProficiencyBonus)
ds_grid_set(itemStatGrid, 19, 0, itemLuckBonus)
ds_grid_set(itemStatGrid, 20, 0, itemAttackSpeedBonus)
ds_grid_set(itemStatGrid, 21, 0, itemCastSpeedBonus)
ds_grid_set(itemStatGrid, 22, 0, itemWeaponMagicDamage)
ds_grid_set(itemStatGrid, 23, 0, itemWeaponPhysicalDamage)
ds_grid_set(itemStatGrid, 24, 0, itemWeaponPoisonDamage)
ds_grid_set(itemStatGrid, 25, 0, itemWeaponToxicDamage)
ds_grid_set(itemStatGrid, 26, 0, itemWeaponBaneDamage)
ds_grid_set(itemStatGrid, 27, 0, itemWeaponFireDamage)
ds_grid_set(itemStatGrid, 28, 0, itemWeaponFrostDamage)
ds_grid_set(itemStatGrid, 29, 0, itemWeaponElectricDamage)
ds_grid_set(itemStatGrid, 30, 0, itemWeaponLightDamage)
ds_grid_set(itemStatGrid, 31, 0, itemWeaponDarkDamage)
ds_grid_set(itemStatGrid, 32, 0, itemTrueMagicDamage)
ds_grid_set(itemStatGrid, 33, 0, itemTruePhysicalDamage)
ds_grid_set(itemStatGrid, 34, 0, itemPoisonDPSBonus)
ds_grid_set(itemStatGrid, 35, 0, itemPoisonResist)
ds_grid_set(itemStatGrid, 36, 0, itemToxicDPSBonus)
ds_grid_set(itemStatGrid, 37, 0, itemToxicResist)
ds_grid_set(itemStatGrid, 38, 0, itemBaneDPSBonus)
ds_grid_set(itemStatGrid, 39, 0, itemBaneResist)
ds_grid_set(itemStatGrid, 40, 0, itemPhysicalDamageBonus)
ds_grid_set(itemStatGrid, 41, 0, itemPhysicalResist)
ds_grid_set(itemStatGrid, 42, 0, itemFireDamageBonus)
ds_grid_set(itemStatGrid, 43, 0, itemFireResist)
ds_grid_set(itemStatGrid, 44, 0, itemFrostDamageBonus)
ds_grid_set(itemStatGrid, 45, 0, itemFrostResist)
ds_grid_set(itemStatGrid, 46, 0, itemMagicDamageBonus)
ds_grid_set(itemStatGrid, 47, 0, itemMagicResist)
ds_grid_set(itemStatGrid, 48, 0, itemElectricDamageBonus)
ds_grid_set(itemStatGrid, 49, 0, itemElectricResist)
ds_grid_set(itemStatGrid, 50, 0, itemLightDamageBonus)
ds_grid_set(itemStatGrid, 51, 0, itemLightResist)
ds_grid_set(itemStatGrid, 52, 0, itemDarkDamageBonus)
ds_grid_set(itemStatGrid, 53, 0, itemDarkResist)
scr_add_item:
Code:
/// @function addItem
/// @description Add an item to a grid

gridToAddTo = ds_grid_get(itemStatGrid, 0, 0);
newItemName = ds_grid_get(itemStatGrid, 1, 0);
newItemAmount = ds_grid_get(itemStatGrid, 4, 0);
newItemDescription = ds_grid_get(itemStatGrid, 2, 0);
newItemSprite = ds_grid_get(itemStatGrid, 3, 0);
newItemScript = ds_grid_get(itemStatGrid, 5, 0);

//Increases the amount of that item if it's already in the inventory
for(i = 0; i < ds_grid_height(gridToAddTo); ++i) {
    if(ds_grid_get(gridToAddTo, 0, i) == newItemName) {
        ds_grid_set(gridToAddTo, 1, i, ds_grid_get(gridToAddTo, 1, i) + newItemAmount);
        return true;
    }
}
//Increase ds grid size by 1
if(ds_grid_get(gridToAddTo, 0, 0) != 0) //Required, since when creating the DS grid, it has a size of 1 already
    ds_grid_resize(gridToAddTo, playerInventoryWidth, ds_grid_height(gridToAddTo) + 1);

//Adds it to the inventory if it's unique
newItemSpot = ds_grid_height(gridToAddTo) - 1;
ds_grid_set(gridToAddTo, 0, newItemSpot, newItemName);
ds_grid_set(gridToAddTo, 1, newItemSpot, newItemAmount);
ds_grid_set(gridToAddTo, 2, newItemSpot, newItemDescription);
ds_grid_set(gridToAddTo, 3, newItemSpot, newItemSprite);
ds_grid_set(gridToAddTo, 4, newItemSpot, newItemScript);
// This for loop should set all the item stats to the correct inventory slots. If not, just delete the for loop and uncomment the paragraph below.
{
var i;
for (i = 5; i < playerInventoryWidth + 1; i++) {
    ds_grid_set(gridToAddTo, i, newItemSpot, ds_grid_get(itemStatGrid, i + 1, 0));
}
}
tl:dr version:
I create a ds grid in obj_inventory. Then I create another, different ds grid in obj_pickup. In the creation code of each obj_pickup I place in the room, I will fill all the variables set inside the ds grid in obj_pickup, which are defaulted to undefined. Then, when the player walks into the object, a collision event takes place, and obj_pickup calls scr_add_item. scr_add_item uses all the variables set inside obj_pickup's ds grid to set obj_inventory's ds grid.

Will this work? Will calling the script from obj_pickup allow the variables from each obj_pickup to autofill the inventory grid?
 
S

Spencer S

Guest
How would this work?
You have no limit on aruments number. Just use argument[N] instead of argumentN.
If you used an array, you could pass the array pointer. Less descriptive, but more flexible...
That's what I tried doing after reading a couple forum posts and the manual, but I guess I did it wrong. How would I do that?
 
Last edited by a moderator:

Dmi7ry

Member
How would this work?
http://docs2.yoyogames.com/source/_build/3_scripting/3_gml_overview/3_scripts.html

And couple words about your code.

1. Never use globarvar. Use global. prefix instead.
2. You don't need ds_grid for simple list. ds_list would be better for this. Or even better just an array.
3. Use accessors. For example, instead of
Code:
ds_grid_set(itemStatGrid, 0, 0, gridToAddToFromItem)
it would be
Code:
itemStatGrid[# 0, 0] = gridToAddToFromItem;
or
Code:
gridToAddTo = ds_grid_get(itemStatGrid, 0, 0);
becomes
Code:
gridToAddTo = itemStatGrid[# 0, 0];
etc.

P.S. But as I already wrote, you don't need ds_grid, ds_list or anything else, because you have no limit on arguments count.
 
Last edited by a moderator:
Top