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

GameMaker [SOLVED] using negative offset to read from buffer_wrap

T

TomSinister

Guest
I was wondering if it was possible to use a negative offset to read values from a buffer_wrap. As an example, say I want to read data from 10 positions behind a buffer_wrap current "seek" position (seek - 10) with the buffer_peek command. If the current seek position is less than 10, will the buffer_read command then wrap around and read from the end of the buffer? or will it cause a compile error?

If this feature is not available in GMS2, I think I can write a workaround by checking to see if the solution to (seek - 10) is negative, and if it is I can add the total size of the buffer to the negative answer, which will result in the same sort of wrapping I am hoping for.
 
Last edited by a moderator:

NightFrost

Member
GML modulo is useless for wraparound counters as it doesn't play by Euclidean division. Taking -2 mod 10 won't give 8 but -2. (So you can't make fast angle changer either by doing angle = (angle + angle_change) mod 360.)
 

TheouAegis

Member
Well then (pos+length) mod length.

Yeah I keep forgetting about that stupid error with negative numbers. Always works on my windows calculator but never in GM. Lol
 
Last edited:
T

TomSinister

Guest
Well then pos+length mod length.

Yeah I keep forgetting about that stupid error with negative numbers. Always works on my windows calculator but never in GM. Lol
Awwwwwww yeaaaaah! this is what i was looking for. Nice, clean solution that i can slap into my if statements, thanks for the help, folks!
 
Top