SOLVED Subtract a specific word from a string

U

uni00

Guest
Since I used enum item{} to make an inventory, the item names in the inventory are prefixed with "item.". I want to reap only this name.
Because you have to create an objname for instance_create() so that the character will drop the item you used.
I want to create "item_draw" this time, but the name in the inventory is "item.draw", so if it is left as it is it will be an error if you specify a nonexistent object as "item_item.draw".
thanks!

Code:
enum item{
none = 0,
draw = 1,
dresser = 2,
ball_w = 3,
ball_b = 4,
ueki = 5,
tubo = 6,
tue = 7,
kagi = 8,
kami = 9,
total
}
GML:
var iid = global.inv[# var_slot, 0];
if (global.item_index[# iid, item_stat.type] == item_type.create) //If the item is food
{//Gain the right amount of health
    instance_create_depth(o_player1.x,o_player1.y,-1001,asset_get_index("item_"+string(iid)));
global.inv[# var_slot, 1] -= 1; //Remove one food item
  if (global.inv[# var_slot, 1] <= 0) //Clear the slot if it is empty
  {
  global.inv[# var_slot, 0] = 0;
  global.inv[# var_slot, 1] = 0;
  }
}
 

Simon Gust

Member
That will not work. The names of the enum and the names of objects are not strings. They will be converted to mere numbers on compile. If you want to have coherent names to your objects you can add another entry to your enum item_stat called name. Then when defining all stats you give each item their name like "draw" and "dresser" and so on. Once this is done you can convert this name to a number
Code:
var name = global.item_index[# iid, item_stat.name];
instance_create_depth(o_player1.x,o_player1.y,-1001,asset_get_index("item_"+string(name)));
 
U

uni00

Guest
That will not work. The names of the enum and the names of objects are not strings. They will be converted to mere numbers on compile. If you want to have coherent names to your objects you can add another entry to your enum item_stat called name. Then when defining all stats you give each item their name like "draw" and "dresser" and so on. Once this is done you can convert this name to a number
Code:
var name = global.item_index[# iid, item_stat.name];
instance_create_depth(o_player1.x,o_player1.y,-1001,asset_get_index("item_"+string(name)));
Thank you. I'm not exhausted, so I will try to realize it by another route
 
Top