• 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!

SOLVED reference unspecified sprites

Hello
I want to do reference instances depending on what kind of sprite they have. Say like ,if their sprite index is armor__1_ , armor__2_ , or armor__3 etc. then do this, if their sprite index is weapon__1_ , weapon__2_ , or weapon__3 etc. do that.
Is this somehow possible?
Is there like a placeholder i can use like
if sprite_index = armor__[n]_
[
do this
]
??
thx
 

kburkhart84

Firehammer Games
I will give you my suggestions below, however, you may want to tell us more about what you are doing, as we may be able to provide a better way to do it.

Is this code that is going to be in the step event of each object? If so, you might be able to take advantage of the parent/child system. I would make a parent object with the code and then make the children just have that parent object. If the child doesn't have a step event, the parent one will run. And if the child does have one, you can call event_inherited() to run the code in the parent step event.
Code:
//parent step event
if(sprite_index == spr_armor1)
{
    //do something
}
else if(sprite_index == spr_armor2)
{
    //do something else
}
//and so on
Then, any children objects that have this object for a parent will automatically have that step event included.
 
I will give you my suggestions below, however, you may want to tell us more about what you are doing, as we may be able to provide a better way to do it.

Is this code that is going to be in the step event of each object? If so, you might be able to take advantage of the parent/child system. I would make a parent object with the code and then make the children just have that parent object. If the child doesn't have a step event, the parent one will run. And if the child does have one, you can call event_inherited() to run the code in the parent step event.
Code:
//parent step event
if(sprite_index == spr_armor1)
{
    //do something
}
else if(sprite_index == spr_armor2)
{
    //do something else
}
//and so on
Then, any children objects that have this object for a parent will automatically have that step event included.
Yeah i see i was being unclear.
I know about parent/child options.

This is for a menu spawning that spawns loot upon pressing a button.
Now i have the parent object handling things like the drag and drop and other general options for the object.
I have multiple child objects right now which are something like: poor armor, better armor, poor weapon, better weapon, epic weapon etc.
Pressing the button spawns the certain child object, eg poor weapon, several times with each different weapon skins and random attributes: armor value, attack value, 💩💩💩💩 like that.
These are randomly gernerated in the create event of the child object.
Now i have a lot of these children or item groups so to say. Like 4 kinds of quality for each light, medium and heavy weapons and about the same for armor, misc. items, spell icons, trait icons etc.
Now what I want to do is avoid having to implement an enormous amount of buttons. I dont want to make a button for every child; every kind of weapon or item.
I want to make a button for weapons, which upon being pressed several times, spawn ALL weapons after deleting the other.
I know how to do all that, the only problem is:
I need a way to define the variables of the child object by sprite "group".

To be clearer:

Button pressed.
obj_weapon_child created
In the create code of the object:
if obj_weapon_child.sprite_index = spr_poor_light_weapon__[n]_
[
attack = blabla
agility = blabla
and so on
]
 
Thats the code for the button to maybe make it clearer:
I am a huge noob at this, so my codes most likely garbage, pls dont mind :)

Create//
list1 = ds_list_create();
list2 = ds_list_create();
list3 = ds_list_create();
(...)

ds_list_add( list1,
spr_poor_medium_weapon__1_ ,
spr_poor_medium_weapon__2_ ,
spr_poor_medium_weapon__3_ ,
(...)
spr_poor_medium_weapon__66_ )


ds_list_add( list2,
spr_poor_medium_weapon__67_ ,
spr_poor_medium_weapon__68_ ,
spr_poor_medium_weapon__69_ ,
(...)
)

left pressed//
global.item_spawn_anti_overlap += +1
if page = 0
{
list = list1
if !ds_list_empty(list2){
page = 1
}
else { page = 0}
}

else
{
if page = 1
{
list = list2
if !ds_list_empty(list3){
page = 2

}
else { page = 0}
}

else
{
if page = 2
(...)

}

}}}}}}}}}

if !is_undefined(list[| 0]) {rdnm1 = list[| 0] }
if !is_undefined(list[| 1]) {rdnm2 = list[| 1] }
if !is_undefined(list[| 2]) {rdnm3 = list[| 2] }
(...)
if !is_undefined(list[| 65]) {rdnm66 = list[| 65] }

if !is_undefined(list[| 0]) {var temp = instance_create_layer(obj_item_spawn_point.x, obj_item_spawn_point.y+20, "hud_layer", obj_poor_medium_weapon); temp.sprite_index = rdnm1 }
if !is_undefined(list[| 1]) {var temp = instance_create_layer(obj_item_spawn_point.x, obj_item_spawn_point.y+110, "hud_layer", obj_poor_medium_weapon); temp.sprite_index = rdnm2 }
if !is_undefined(list[| 2]) {var temp = instance_create_layer(obj_item_spawn_point.x, obj_item_spawn_point.y+200, "hud_layer", obj_poor_medium_weapon); temp.sprite_index = rdnm3 }
(...)
if !is_undefined(list[| 65]) {var temp = instance_create_layer(obj_item_spawn_point.x+500, obj_item_spawn_point.y+910, "hud_layer", obj_poor_medium_weapon); temp.sprite_index = rdnm66 }
 
C

CruelBus

Guest
Not sure if this will help, but for referencing similarly named sprites, I use something like:
Code:
armrSPR=2;
sprite_index=asset_get_index("spr_armor_"+string(armrSPR));
 
C

CruelBus

Guest
You might be able to use
sprite_get_name
then parse that string for what you're looking for.
 

kburkhart84

Firehammer Games
Do you then also realize that you can add a second layer to the parent/child fun? Your parent could be the button or whatever. The children of that could be armors, weapons, etc... then those could have separate children as well.

That said, I think you are better off using something like structs to handle it, since you are using 2.3+. A struct could contain a number to indicate what it is(armor, weapon), then another could indicate the level of armor/weapon, then a few more numbers would indicate strengths, defense, etc... If you store it in a struct, then you could use the same object for ALL of them and just use the struct to know what it actually represents. This is likely better than trying to use the sprite to do so, and would give you the freedom later on to change the sprite name or make other changes without affecting the functionality.
 
Do you then also realize that you can add a second layer to the parent/child fun? Your parent could be the button or whatever. The children of that could be armors, weapons, etc... then those could have separate children as well.

That said, I think you are better off using something like structs to handle it, since you are using 2.3+. A struct could contain a number to indicate what it is(armor, weapon), then another could indicate the level of armor/weapon, then a few more numbers would indicate strengths, defense, etc... If you store it in a struct, then you could use the same object for ALL of them and just use the struct to know what it actually represents. This is likely better than trying to use the sprite to do so, and would give you the freedom later on to change the sprite name or make other changes without affecting the functionality.
that sounds promising. ill look into that.
thank you
 
Top