• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Help with Script Broken Please :)

simes007us

Member
Hi Everyone,

I'm having a problem with a script I wrote. It checks how big a ds_list that is in an object (loot) and picks a irandom value in the range. 0-ds_list_size

The ds_list in "loot" contains objects. Once the number value is picked it's supposed to create the item in the ds_list with that number.

Code:
/// @param playerilvl

var playerilvl = argument0

var item = irandom(ds_list_size(loot.lootlist))

var lootlvl = irandom_range(playerilvl-2,round(playerilvl*1.4))

if (lootlvl <=0)
lootlvl = 1
drop = instance_create_depth(x,y,-5,loot.lootlist[| item])

drop.rank = lootlvl
This produces an error saying that "item" is of incorrect type. The type being "undefined". And I have no idea why. Any suggestions?
 
This produces an error saying that "item" is of incorrect type. The type being "undefined". And I have no idea why. Any suggestions?
Show us the exact error that is being thrown, not your interpretation of it. The actual error will point us to the problem better than what you have currently provided.
 

Simon Gust

Member
This fixed it ^ not entirely sure why the -1 has to be inside the brackets. @TheouAegis thanks :)
The -1 is a regular thing you'll use when you bring together real size and lengths of indexes.
Imagine you list has 40 entries. Each entry has an index, starting at 0. That means the last index will be index 39, even though there are 40 of them.
If you use irandom(ds_list_size()) now, or translated to irandom(40), the 40 as a number is included and your random function can sometimes spit out 40, which is not a real index.

If you would put the -1 outside both brackets, it would fake the result into then giving you a number from -1 to 39, and -1 is also not a real index.
 
Top