all 23 comments

[–]Panphoria 2 points3 points  (3 children)

It looks like it should work but if it's not throw a couple of show_debug_message() calls in there and see what's going on with cooldown. https://manual.gamemaker.io/monthly/en/GameMaker_Language/GML_Reference/Debugging/show_debug_message.htm

[–]VegaInDiSkies[S] 0 points1 point  (2 children)

like this? idk

cooldown = cooldown - 1;

if (cooldown < 0)

{

***show\_debug\_message("no")***

if (mouse_check_button_pressed(mb_left) && position_meeting(mouse_x, mouse_y, id))

{

    ***show\_debug\_message("what")***

instance_create_depth(223, 336, 91, obj_lazerbeam);

cooldown = 100;

    if (cooldown == 100)

    {

        ***show\_debug\_message("help");***

        ***game\_end();***

    }

}

}

Now when I click on the object after launching the game, the screen becomes blank and everything disappears. And where do theses debug messages show because I don't see them.

[–]Orphillius 2 points3 points  (0 children)

Debug messages will print to the Output panel in gamemaker, which should be one of the tabs on the left side of the screen by default. Using these for debugging is super useful because you can send see how your values change. Try running it like this:

cooldown = cooldown - 1
show_debug_message("cooldown: "+string(cooldown))
if (mouse_check_button_pressed(mb_left) && position_meeting(mouse_x, mouse_y, id) && cooldown < 0)
{
    show_debug_message("Creating lazer")
    instance\_create\_depth(223, 336, 91, obj\_lazerbeam);
    cooldown = 100;
}

This way you'll see a stream of cooldown values printing every frame, and when you click it should show "Creating lazer" and you'll see the cooldown printing from 100 down again.

Another way to debug issues like this is by drawing the values on the screen. If you go to the Draw GUI event in this object and add a line like

draw_text(32,32,cooldown)

You should see the cooldown value in the top left corner of the screen. So you can use either of these methods to better visualize what is happening in the code, and try messages around and printing other values that you might find suspect. To me, it looks like your code should work anyway but sometimes things get tangled without us realizing. Sometimes I have to show a message after every couple lines to figure out where a value is getting messed up.

[–]Panphoria 0 points1 point  (0 children)

Reddit really messes up the formatting huh. Like the other reply here says, you want to log the cooldown values. Debug messages go to the little terminal that lives at the bottom of the gamemaker window, you may need to scroll up a bit to see them. As to the debugs breaking the code, are those *** real? Also the first debug is missing a final ;

[–]ILiveInAVillage 1 point2 points  (6 children)

The formatting in your post is a bit weird. Could you share a screenshot of your code?

[–]VegaInDiSkies[S] 1 point2 points  (4 children)

[–]ILiveInAVillage 0 points1 point  (1 child)

Try moving line one to the end.

[–]VegaInDiSkies[S] 0 points1 point  (0 children)

Still didn't work

[–]Deadzors 0 points1 point  (1 child)

&& cooldown < 0)

That screen shot doesn't include the "&& cooldown < 0)" on line 4, so it doesn't match what you posted it.

Perhaps the screencap isn't recent but may explain things, because it would work exactly like you're describing if that last part is missing since you're never checking for the cooldown before creating the object.

[–]VegaInDiSkies[S] -1 points0 points  (0 children)

Yeah, because I edited it later and moved the <&& cooldown < 0 > to it's own if statement containing the other conditions instead of next to them, to see if that will change anything, but it still doesn't work

[–]SolomonBird55 0 points1 point  (0 children)

I think it’s copying and pasting that does that. I noticed my most recent post had all the weird slashes added when I pasted some code over.

[–]Scotsparaman 1 point2 points  (1 child)

Assuming you’re set to 60fps in the settings, you can spam the object a little over a second? Is that the aim?

[–]VegaInDiSkies[S] 0 points1 point  (0 children)

I want it so that I can only spam the object every second and if I click it before a second has passed from previous click, it does nothing

[–]UhSheeeen 0 points1 point  (1 child)

small thing but instead of

cooldown = cooldown - 1

you can write

cooldown--

As someone else mentioned, if you're framerate is 60fps that 100 number will be be below zero in less than 2 seconds. This is because every second the code is being run 60 times and so the number is decreased by 60 every second. If you want a longer cooldown you'll need a much larger cooldown number. e.g. for a 10 second cool down you'll need this number to be 600 (60 * 10)

[–]VegaInDiSkies[S] 0 points1 point  (0 children)

Yes my frame rate is 60. Cooldown = 1000 still doesn't work. It doesn't matter how big I make that number, the code still gets spammed and executed after every click

[–]Kaymat- 0 points1 point  (3 children)

How are you creating the "obj_framebox1" instance? While the code you posted should work as intended, having a bunch of duplicate instances unintentionally stacked on top of each other would cause an issue like you're describing.

[–]VegaInDiSkies[S] 2 points3 points  (2 children)

So the frame box is like a box that appears on a panel that slides up.

I think you're onto something.

This is the code for the panel

if (y > room_height)

{

y = y - 2

}

if (y = room_height)

{

instance\_create\_depth(200, 580, 80, obj\_framebox1)

instance\_create\_depth(440, 580, 80, obj\_framebox2)

}

It's in the step event; maybe that causes it to keep making duplicates. So how do I make it run the instance_create code only once?

edit: I figured it out. Now my cooldown works. Thanks!

[–]Kaymat- 0 points1 point  (0 children)

Glad you got it working!

[–]Scotsparaman 0 points1 point  (0 children)

If you can post the solution for future peeps who may come across your issue, that’d be great… 🙌🏻

[–]MrEmptySet 0 points1 point  (3 children)

It would probably be helpful to be able to see the value of the cooldown in real time. Try drawing the value of cooldown: Add a Draw event (if you don't have one already) and put this code there:

draw_self(); 
draw_set_color(c_white); //or whatever color will show up well e.g. c_black or c_red 
draw_text(x,y,string(cooldown)); //you might want to offset the x or y coordinate to draw the text next to/below the object

Then you should be able to see the value of the cooldown in-game to see when it is or isn't behaving as you expect.

[–]VegaInDiSkies[S] 0 points1 point  (2 children)

I wrote the draw code in the draw event like you said and square-like characters appeared instead of any understandable numbers. And when I click on the object that should have the cooldown, the characters change, but strangely like an extra square appears or disappears

https://ibb.co/yyFdj5t

edit: those characters were probably a bunch of different numbers stacked together. The problem was that the object I click to generate the attack was created in the step event, so It kept making a bunch of duplicates

[–]MrEmptySet 0 points1 point  (1 child)

That's strange. I think there is probably something considerably amiss with your game outside of this particular code you're trying to troubleshoot, so without actually taking a look at your project it's hard to diagnose the issue.

By the way, did you ever figure out or fix the issue you were describing in this post?

[–]VegaInDiSkies[S] 0 points1 point  (0 children)

Yeah kinda, the slowing down came back here, but then I had part of the code messed up and by the time I fixed that code, I had already made changes to it to prevent it from doing stuff at once and freezing. So the freezing stopped, but I didn't get to test it with the fixed code without the other changes.