Can't get code to work for rewards

C

Callam

Guest
Hi, so i have a game where you can find treasure chests. each chest has its own set of rewards for example

chest1: 1-2xp, 3-5gold
chest2: 2-4xp, 5-7gold, 1-2emeralds

etc

I have a chest object that creates each of the objects (xp etc) , which then shoot off to the hud element and add to the respective counters before disappearing. That all works fine, however upon trying to add more chests and code it in, the xp etc either stops being counted after the collision or counts sporadically. ive tried many different things and cant get it to work so heres my code. hopefully someone will be able to help.

obj_game
create event:
global.chest1 = 0
global.chest2 = 0

obj_chest1
left pressed
global.chest1 = 1

obj_chest2
left pressed
global.chest2 = 1

obj_xp_drop
if global.chest1 = 1
{
global.playerxp += irandom_range(1, 2)
global.chest1 = 0
}
else
if global.chest2 = 1
{
global.playerxp += irandom_range(2, 3)
global.chest2 = 0
}
 
G

Guitarmike

Guest
It's a little hard to understand what you're trying to do exactly. But it seems to me you might be going about it the wrong way. Can you just make a single obj_chest object (rather than obj_chest1, obj_chest2, etc.)? Then give it variables representing the rewards.

Code:
obj_chest
//Create
// All of these values can be overridden in each instance's "instance create" code...
gold_min = 3;
gold_max = 5;
xp_min = 1;
xp_max = 2;
emeralds = 0;

empty = false;  //to avoid double-collection from the chest.

//collision with player (or mouse click or whatever)
global.playerxp +=  irandom_range(xp_min, xp_max);
global.playergold +=  irandom_range(gold_min, gold_max);
...

empty = 1;
 
C

Callam

Guest
hi, thanks for your response, reading back i see that i didnt explain thoroughly. allow me to try again.

So my game idea is similar of that to Treasure Isle (random gameplay video for reference:
). The concept is simple. Dig up dark squares to possibly find treasure and earn xp/gold etc.

I want to take that concept but also incoparate multiple different kinds of chests. For example from levels 1-5 i want chest1-chest5 to have a chance of randomly spawning. Each chest has its own rewards. (download link for my game plan: https://www.filehosting.org/file/details/781930/Treasure Isle Game Plan.txt )

Right now i have a black tile that has a chance of spawning a specific chest. Each chest is opened by clicking it. I have an object for each variable, xp, gold, energy and emeralds. Since im only using one of each object i need it to be able to work out which chest created it and assign it variables based on that chest. i could sit and make like 50 of each object with differing rewards based on the chests rarity but after making a game with over 1000 objects id like to avoid that at all costs.

So to some it up i need the xp object to work out which chest it came from and assign random amounts of xp relevant to the chests rewards.

Hopefully this is a better explanation. If not i can happily show you gameplay or upload the project so people can have a poke around.

Thanks
 

Filkata

Member
It sounds like you are having some issues with the collision, it is counted more than once? Some more explanations would help as it is not very clear at the moment I am afraid. For what event is the code in obj_xp_drop that you posted?
 
C

Callam

Guest
right now ive temporarily made multiple of the same xp_drop object with different values. basically what i want to happen is when a chest is opened the xp object shoots of to the hud icon, adds a random amount of xp and then destroys itself.

currently for the object xp_drop i have:

Create:
if point_distance(x, y, obj_xp.x, obj_xp.y) > 1
{
move_towards_point(obj_xp.x, obj_xp.y, 30);
}
else speed = 0;

Collision with obj_xp (HUD icon):
global.playerxp += irandom_range(1, 2)
instance_destroy();

Outside Room:
instance_destroy();

This works perfect as a single entity. However if i try to incoporate multiple chests into the xp drop code it still sends the xp drop flying off to the hud but upon collsion it either adds nothing (99% of the time) or adds the wrong amount. I feel like its such a simple fix but ive tried so many different ways i dont know what else to do

heres a download link to as i dont think this explanation will help much as its hard to explain whats happening https://www.filehosting.org/file/details/782064/Treasure Isle.gmx.rar
 
Top