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

Windows issues with numbers

F

Florian

Guest
Hi there,


I recently started goofing around on GMS2.

Currently working on a roguelike project, my first incomprehension came with damage calculation.
Right now it's overly simple : each time I bump into the enemy he loses 5HP.

So I have something like :

hp_enemy -= 5 ;
if (hp_enemy <= 0)
{
instance_destroy(obj_enemy) ;
}

Everyrhing works just fine, except that in fact the enemy loses 10HP :
hp_enemy = 20 in the create event, and he dies in 2 hits instead of 4.

I skipped that part for a moment and moved on.

Now improving the combat system I started using random values.
But when using random(100) or random_range(0,100) the value always stay <=50.

What am I doing wrong here ?
I find it strange to systematically have a x2 error factor in everything I try.

Thanks by advance for any kind of advice here !
 

Simon Gust

Member
How have you set up the collision for the player and the enemy? What does the code look like?
The second issue is probably just it being random but the same random everytime.
Try putting a randomize() at the start of the game.
 
F

Florian

Guest
Hey,

Thanks for the quick reply.
I'm already using randomize(), but after literally thousands of operations I have yet to see a result >50.

Regarding collision here is how I defined player movement toward up in step event :

if keyboard_check_pressed(vk_numpad8)
{
if !place_meeting(x,y-64,obj_enemy)
{
y += -64
}
else
{
script_execute(scr_melee())
}
}

the scr_melee script is where I put :

obj_enemy.hp_enemy -= 5 ;
if (obj_enemy.hp_enemy <= 0)
{
instance_destroy(obj_enemy) ;
}
 
F

Florian

Guest
Ok I found what was wrong with random.
Stupid mistake sorry for that (I was only displaying the value when it was <50...)

I still can't figure out why the enemy dies in two hits on the other hand.
 
Remove script_execute() from your code.

Your script is running twice because you have script_execute(scr_melee())

When you use script_execute, just use the script name without the parentheses() or the script will run, then script_execute() will then run whatever script has the same return value that scr_melee() has. By chance in your case, they must be the same.
 
F

Florian

Guest
Nice thanks a lot IndianaBones !

I know yes, but only one enemy for now.
I won't go very far with this first project I'm just learning for now ;)
 

FrostyCat

Redemption Seeker
I won't go very far with this first project I'm just learning for now ;)
If you're going to be learning, at least learn the proper way where you know the difference between objects and instances. It's not all that hard.

When you're in a room full of men, "the man's hair colour" becomes a useless reference, and if you use it the obvious follow-up is "Which man?". In contrast, "the hair colour of the man I just walked into" makes better sense. You can answer that with a uniquely identifying name (e.g. John Jackson), and then use that name in place of the general term (e.g. John Jackson's hair colour). The equivalent of that in GML is denoted by instance_place(), and that returns an instance ID specifically answering the question "Which one?" (or the special value noone if there had been no collision).

Add a parameter to scr_melee by using argument0 instead of obj_enemy as the subject.
Code:
argument0.hp_enemy -= 5 ;
if (argument0.hp_enemy <= 0)
{
    instance_destroy(argument0) ;
}
Then pass an instance ID returned by instance_place() into the script, after checking to see that it isn't noone.
Code:
var inst_enemy = instance_place(x, y-64, obj_enemy);
if (inst_enemy == noone)
{
    y -= 64;
}
else
{
    scr_melee(inst_enemy);
}
Also note how I posted my code between [code] and [/code] tags. This is how you should post code going forward, not just pasting it in plain formatting and thinking you're done.
 
F

Florian

Guest
Thanks a lot FrostyCat, better sooner than later you're right !
 
Top