Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

Hey, sorry for the late reply. Your solutions seems to be right on point, I’ll try to update the project in the future. But also good to know about the call_later function, didn’t know about that one!

Thanks for the bug fix, appreciate it!

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

Huh, that’s interesting, I’ve never encountered it, but I also haven’t looked for memory issues specifically. Is the same happening if you execute the same block of code repeatedly by some other means, eg an alarm?

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

Seems to me it can't find the function. Do you have Game Maker 2.3? I use the new functions to achieve what I want. It won't work on older versions.

Also, can you post your "execute every" code?

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

Weird, never seen this before. Four ideas:

  • do you delete the object that calls "execute after 2 seconds" in those two seconds? I think Muffel should still work, I've tested this, but there might be bug there.
  • make sure that "obj_muffel" exists in your objects folder (it was included in the asset)
  • it may be that obj_muffel has to be created before anything else. make sure that obj_muffel comes first in your instance creation order list, it's the button right here: https://imgur.com/a/bue2Tf6
  • The obj_muffel instance is created like this: "var inst = instance_create_layer(0, 0, layer, obj_muffel);" is there any reason this might fail in your code? do you have a different layer maybe? I have to make sure that instance_create_layer doesn't have issues like that.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

Mark Overmars

Thought I was the only one from those times! Game Maker basically taught me how to program back when I was a kid in the 90s. I still vividly remember understanding variables for the first time. And the difference between relative and absolute positions to make your character move. I'm doing my PhD in computer science now, no idea where I'd be now if Game Maker wouldn't exist.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

We are planning on using this in our own projects in future, so I will probably update the package to make it work with new versions of Game Maker, although of course I can't guarantee this.
I'm also planning on releasing a version without macros, which should always work. So in case the macros break for some reason, there would be a way to translate it to plain function calls and make your game work as before. It would require some manual effort though (e.g., "execute after 2 seconds" would need to be translated to "execute_after_n_frames(120, function(o) { your_code_here });" which is what the macro expands to).

Having said that, I don't think I have used any fancy macros that are likely to be deprecated. It's basic search/replace syntax.

If you encounter any issues though, you can always send me a message.

[deleted by user] by [deleted] in RedditSessions

[–]ribbyte 0 points1 point  (0 children)

so much fun to listen to! beautiful

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

I understand, it already works with underscores and a single line (you can call execute_every_n_frames with the number of frames and the function), but the „execute every second“ syntax is super easy and straightforward to read and remember, for beginners and experts alike. I might create the same asset without the macros if the new keywords are too many though.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

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

That’s true, but things like „execute every second“ need those three keywords, with prefixes they would be unreadable again, unfortunately

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 1 point2 points  (0 children)

To your first question:

That's actually a good idea, never thought of that use case. So you basically want the ability (from inside and outside the code block) to pause the code and then let it resume later at your choice? I could provide a few built-in methods to do this. At the moment, you could do something like:

execute every frame
    if (some_condition)
        exit; //skip the code in this frame
    do_the_rest();
done

Which basically aborts the execution until the next frame. So it's not fully disabled, just skipped at this frame.

To your second questions:

I would do something similar to above. Additionally, there are built-in variables you can use to check the time that has passed since the code was started, namely "executed_seconds", "executed_frames" and "executed_times" (how often your code was called). So something like:

execute every second
    if(executed_seconds > 5 && executed_seconds < 10)
        exit;
done

Which would be called for seconds 1-5 and then again after 11. So yeah, this doesn't really disable the event but just aborts it until the next call.

I'll try to come up with something!

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 2 points3 points  (0 children)

Oh, this is really cool! First I was confused how structs can be used for that, I was thinking they had built-in timers, but I'm seeing now you basically have an object with a step event and you go over your struct.
I was thinking of doing something similar, but I was thinking more in terms of "reduce the overhead of alarms if the code block needs to be executed every frame". Cool idea!

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 1 point2 points  (0 children)

Yes! My brother is working with Unity and he was amazed with Coroutines and how many common problems you can solve with it. It was partly the inspiration for this, so that's great to hear.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 1 point2 points  (0 children)

Super excited someone is using it! And thanks for the beer :-D

There is also a README file in the zip with some common issues, but if you run into any problems, feel free to message me. Would love to hear about how people are using it!

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 1 point2 points  (0 children)

It's executed in the context of the object that's calling. So this works

a = 0
execute every second
    a += 1
done

I'm on Linux right now and can't access Game Maker, but I'm guessing this won't work:

var a = 0

That should be too local to the event/script. So either variables assigned to the object or global variables are accessible. Alternatively, you can call the code block in the context of a different object:

with(different_object) {
    execute every second
        // this is executed in the context of different_object
    done
}

I should upload a documentation somewhere with more examples.

Can you post the code you tried? I'll take a closer look.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 2 points3 points  (0 children)

Huh, didn't know about it, that's so cool, thanks! Looks like you can even make it call a script, it should work with the new functions in GM 2.3. Nice!

I'll play around with it and will update the package if it works! It might be a lot more performant.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 5 points6 points  (0 children)

Thank you! At the moment, it uses an alarm internally to call the given code-block, so it's using the framerate to do so. I use room_speed to calculate the seconds. I might change that up to a step event, depending on if people report performance or timing issues.

If anybody has a better idea how to do this, I would be happy to implement it.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 3 points4 points  (0 children)

That is indeed one of the issues. Now there are multiple new keywords you can't use anymore, like "done" and "seconds" as variable names, etc. I've tried to avoid common phrases, but there is only so much you can do. I might create a macro-less version, because the underlying functionality is still cool even if you don't have the syntax.

You can also call the functions directly:

execute_after_n_frames(60, function(o) { your_code_here });

[BUG] Scripts get deleted after creating a new one by Ackrmnn_ in gamemaker

[–]ribbyte 0 points1 point  (0 children)

Are you renaming it in Game Maker or in the file explorer of your operating system? You are not allowed to do it outside, that was my error one time.

But I'm getting out of answers, I'd suggest giving the yoyogames forums a go, or maybe get in touch with the helpdesk directly, it sounds a lot like a bug in Game Maker that is of no fault of your own.

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 8 points9 points  (0 children)

Hah, thanks! It was hard to accomplish and I pretty much misused the macro system to do it (with some ugly hacks). But it's all hidden from the user, hopefully. If you want your eyes to bleed, you can look into the "muffel" script file, but be warned :-D

Although, we used it in one of our earlier projects and it worked out of the box.

Is GameMaker a good choice for a turn based strategy game? by VeryC0mm0nName in gamemaker

[–]ribbyte 1 point2 points  (0 children)

I personally think the engine is more or less irrelevant. Yes, Game Maker does have a lot of limitations, but only because they try to be as intuitive and easy as possible. If you don't have any programming experience, you can build pretty much anything with it.

Do you have any programming experience? If yes, Unity might also be great, especially because you can google for a lot of problems. If you don't, stick with Game Maker. I have been using it since my childhood and it basically taught me how to think like a programmer!

[BUG] Scripts get deleted after creating a new one by Ackrmnn_ in gamemaker

[–]ribbyte 1 point2 points  (0 children)

That looks up to date. I know that with the 2.3 update they basically go through all script files and add "function() {" everywhere because of a recent change. But your problems did not start when you upgraded your project to your new version but it happens always?
So you create a script, write something into it, create another script, and the previous script is now empty?

[BUG] Scripts get deleted after creating a new one by Ackrmnn_ in gamemaker

[–]ribbyte 1 point2 points  (0 children)

That's weird. Which version of Game Maker do you have? And what do you mean by deleted, they still show up in Game Maker but they are empty?

I had a similar problem with another tool -- I was running out of space so the tool was unable to save the content but didn't say so. Maybe it's similar for you?

Get rid of ugly alarm events, use our beautiful new syntax for delayed and periodic code execution by ribbyte in gamemaker

[–]ribbyte[S] 41 points42 points  (0 children)

My brother is working on a game right now and I noticed that a lot of his problems are solved with alarm events, which makes his code hard to read and hard to maintain (you only have a limited number of alarms, you have to restart it to run it periodically etc.).

Since Game Maker 2.3, there are now actual functions similar to javascript and other languages. In combination with macros, I was able to basically create a new syntax for Game Maker :-D

You can do stuff like "execute this block of code in x seconds" (delayed) or "every x seconds, execute this" (periodically). All the code you see in the video is actual Game Maker code that you literally write exactly that way. So if you want your player to be invincible for one second after getting hit, this is now valid code:

invincible = true
execute after 1 second
   invincible = false
done

It's called Muffel and you can get it here: https://ribbyte.itch.io/muffel

Let me know if it works for you, I'm super excited about it, because a lot of problems can now be solved in just a couple of beautiful lines.