• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

HELP ME WITH VALUES!!

reipor

Member
well, I've been starting a project for a card game and I want to create a value system, when a card is chosen the player will gain the value of the card, but the value goes up infinitely, I would like the value to remain without going up, I want to do a system based on

value = 0
if card = X{
value + = X
}

MY CODE:

plz help me ;-;
 
Last edited:

Tony Brice

Member
I'm not going to get to into how long-winded the code is, with all those repeated if statements, but your issue could be:

Code:
if card = card_01 {
  sprite_index = card_01
  global.value =+ 1
}
No semi colons on the end of the lines probably isn't causing an issue here but it's good practice to use them. However, global.value =+ 1 doesn't look right. Should be +=, unless I'm missing something here.

Code:
if (card == card_01) {
  sprite_index = card_01;
  global.value += 1;
}
is how I'd write that particular bit.
 

reipor

Member
I'm not going to get to into how long-winded the code is, with all those repeated if statements, but your issue could be:

Code:
if card = card_01 {
  sprite_index = card_01
  global.value =+ 1
}
No semi colons on the end of the lines probably isn't causing an issue here but it's good practice to use them. However, global.value =+ 1 doesn't look right. Should be +=, unless I'm missing something here.

Code:
if (card == card_01) {
  sprite_index = card_01;
  global.value += 1;
}
is how I'd write that particular bit.
i made this code to know de value:

Code:
draw_text(10, 10, "VALUE: "+string(global.value))
is the problem on this code?

because i still with the same problem
 

Trandoxiana

Member
What event is this in? If it is the step event, and not inside another if statement, it could just be repeating this every frame, and constantly adding to 'value'. And, just like Tony Brice said, you need to switch the plus sign and equals sign. To increment a variable it's "var += 5;". I don't know how the rest of your code works, but it's possible that all you need to do is put all of those if statements inside one large if statement that only activates when the player receives a card. So:
GML:
if (card_recieved)
{
//all of your if statements inside here
card_recieved = false;
}
This way, the code runs the if statement when the player receives a card, and only runs it once. All you need to do is make sure you set card_received to false at the end of the large if statement, and you set it to true when the player receives a card. Hope this helps!
 
Top