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

GML String functions that start at 0 instead of 1

andev

Member
GM Version: Studio
Target Platform: All
Download: Download
Links: <N/A>

It bothers me that the string functions start at id 1 and not 0, because it means you have to add offsets sometimes. So I wrote some pass-through scripts that fix it. Further reading.

All scripts are ready to drag straight into your project at once quickly for maximum convenience. They look like this:
Code:
///str_char_at(str, index)

return string_char_at(argument0,argument1+1);
So now to get the first character in a string, you look up ID 0 (not ID 1).

Another example is:
Code:
///str_pos(substr, str)

return string_pos(argument0,argument1)-1;
Which will return -1 when it can't find the string (and not 0). Same logic as above applies too.

Download

If I've missed something or something doesn't work, let me know, I'll fix it asap. Thanks
 
Last edited by a moderator:

chance

predictably random
Forum Staff
Moderator
Nothing wrong with your approach. But adding scripts to simply increment the position index doesn't seem worth the effort -- to me, at least. And barely worthy of a tutorial submission.

But I suppose the GML indexing convention could be really bothersome to some people. So perhaps they'll use your approach.
 

andev

Member
Thank you for approving it even though it's barely worthy! I sympathise that it's very minimal and not a tutorial but there doesn't seem to be a "resources" subsection anymore which would probably suit this submission a little better. I know this doesn't save that much time, which is why I've put the scripts in a folder rather than putting them in a .gmz or pasting them as code here. But if you wanted to do this, downloading someone elses would be a lot more appealing than writing your own, if you just want to get on with your project.

Currently I'm working on something that's very heavily reliant on the string functions, and large number of the bugs I've crushed so far have been to do with me getting this offset wrong, because there are so many other offsets being added as well. I feel like if it's useful to me I should share it, and if it's any consolation, if someone else had made this before me and I'd seen it, I'd have definitely clicked download.

Thanks again!
 
Top