ds_map question

Smenkare

Member
I have equipment system written in ds_map. When i click in inventory some piece of armor i have code similar to this.

with(oPlayer)
{
oPlayer.sprite_index = ds_map_find_value(armory[0],"spriteIdle");
oPlayer.equiped = ds_map_find_value(armory[0],"attackSprite");
}

with(oDamage)
{
oDamage.damage = ds_map_find_value(armory[0],"damage");
}


It changes player object idle sprite and damage of damage object. First question is: is there a better way to do thing like this (changing variables). Maybe my idea of doing this is stupid, i dont know. My second question is:


if (key_attack && cooldown < 0)
{
sprite_index = equiped;
cooldown = 60;
}

It doesnt work. It seems that i cant use sprite as a variable. So how can i take data from ds_map to change sprite not of a player object but of some of his actions?
 

samspade

Member
Doing an inventory with a map system like that is fine. My only question is you appear to have an array of maps. Nothing wrong with this, but it might be the type of thing where using an enum would make things a little more clear.

There's also nothing wrong with assign a sprite as a variable. So if it isn't working it means that there's some other reason. Perhaps your map isn't returning the right value or maybe cooldown isn't getting below 0. Or perhaps your sprite index is being reset somewhere later in the code.
 

Smenkare

Member
Create Event
//Declaring a variable with sprite inside
attacking = sPlayerAttack;


Step Event

if (key_attack)
{
//Using it
sprite_index = attacking;


}

so for example this should work?
 

samspade

Member
Create Event
//Declaring a variable with sprite inside
attacking = sPlayerAttack;


Step Event

if (key_attack)
{
//Using it
sprite_index = attacking;


}

so for example this should work?
Assuming no other code effects it, yes. (given that everything else is set up correctly as well - e.g. sPlayerAttack is a sprite, key attack is a variable which can be true etc.)
 
Top