Gamemaker clean text wrap5/11/2023 I'm looking forward to working through the official tutorial with my nephew and maybe making some small games. I didn't want to keep tinkering, so I dropped in some floor calls and moved on.Īnyways, this was some fun tinkering. When I tried to test the behavior, I ran into a bug where original_wrap hung indefinitely on some inputs (the existing test triggers this, if you want to uncomment and run). I'm not sure because GML has typeof for typechecks ( is_real in 1.4, which feels very PHP 3), but this is probably well-copy-pasted newbie code. I'm pretty sure the (argument0 mod 1 = 0) exists to type-check if argument0 is an integer or real. The commented-out testcase is, I think, about the broken behavior with regards to reals. show_debug_message("real failed " + string(i) + " orig " + string(orig) + " new " + string(new)) Show_debug_message("int failed " + string(i) + " orig " + string(orig) + " new " + string(new)) make this easy to spot in the build output I generated a golden master test suite to exercise a bunch of test data, though I didn’t go all the way into property-based testing: I know there’s 3rd-party test library but I wanted to hand-roll to see more moving pieces. Which felt a little roundabout for specifying that I wanted it to run at startup, but I’ve barely touched the manual so I’m probably missing something obvious. To test it, I created another script called test and invoked it from an object’s create event. I can’t unimport/shadow the global max and min, the convention seems to be to use a leading underscore for colliding names. In dev I got a compiler error for referencing argument1 before argument0 – I’m not sure what that could be but look forward to reading the manual. Some oddities, like JavaDoc instead of a function signature, so arguments have automatic names (reminds me of perl 5). ![]() Return (((value - _min) % range) + range) % range + _min Var range = _max - _min + 1 // + 1 is because max bound is inclusive Var _max = floor(max(argument1, argument2)) Var _min = floor(min(argument1, argument2)) Calls floor() on reals, but GML's modulo is doing something weird and original_wrap just hangs indefinitely on some values anyways so oh well. Returns the value wrapped to the range (min and max can be swapped). / value The value to wrap into the bounds I saved the above script as original_wrap and created my own wrap implementation: So for practice with GML and the IDE in general, I rewrote it. This is probably hot-path code that runs every frame, but it has branches inside a loop for something that could almost certainly be an arithmetic one-liner. While (argument0 > argument2 || argument0 argument2)Īrgument0 = argument1 + (argument0 - argument2) Returns the value wrapped, values over or under will be wrapped around There’s a visual in the video at 5:30 that makes it real clear. So wrap(5, 0, 9) is 5 because it’s in the bounds, but wrap(11, 5, 9) is 6 because it wraps 2 past 9. The third script presented at 5:18 in the video was wrap(value, min, max) which wraps values that exceed the min or max back around to the other side. ![]() ![]() In GML, a “script” is roughly a singleton static method object used to centralize game state or encapsulate snippets of functionality. On that last channel I saw a video on Useful Scripts for GMS2 presenting five code snippets. All three of those channels are worth clicking around on as they have other good playlists or one-off videos. There’s some great video tutorials on YouTube showing how to make games like NES Zelda, Farming RPG, and Platformer. I’ve been mostly coding Haskell the last few weeks, so there’s a bit of whiplash moving between the two. Little more OO, little less coercion, but it feels similarly very focused on its niche without much experience behind it. The games are coded in “GameMaker Language”, which is approximately PHP 3. And this week version 1.4 (with a free trial and discounted upgrade to version 2) is on sale cheap. Pricing is reasonable, it’s $100 to export desktop games, couple hundred more to export to iOS + Android, HTML 5, even PS4 and Xbox. If you’re curious, there’s a ~90 minute tutorial playlist that’s easy to skim as a demo. It’s even been used in some highly polished and popular games. It’s a nice toolkit and IDE for games, very beginner-friendly, with a friendly community. I’m learning GameMaker Studio 2 because my 10-year old nephew wants to make video games (and the 10 year old inside of me wants to make video games, too). Peter Bhat Harkins Arithmetic Wrap in GMS2 ◰
0 Comments
Leave a Reply. |