Log In  

Wait:

FUNCTION WAIT(FRAMES)
 FOR I=1,FRAMES DO
  FLIP()
 END
END

Usage:

Wait(30) pauses cart for 30 frames.

Grab pixel color

FUNCTION GET_PIXEL(X,Y)
 RETURN PGET(X,Y)
END

Usage:

X=GET_PIXEL(50,40) Gets the color of the pixel at 50,40 and assigns it to X

Get map tile

 FUNCTION GET_MTILE(X,Y)
  RETURN MGET(X/8,Y/8)
 END

Returns map tile at x,y

Mini fget mget

 FUNCTION GETMFLAG(X,Y)
  RETURN FGET(MGET(X/8,Y/8))
 END

Returns flag of map tile at x,y

P#135412 2023-10-04 18:17

1

Just curious, what's the advantage of the GET_PIXEL function over just saying Z=PGET(X,Y)?

P#135414 2023-10-04 18:34
3

you can also write

GET_PIXEL=PGET

?GET_PIXEL(1,1)
P#135415 2023-10-04 18:40

@2bitchuck

To save space. Sometimes of you are using PGET a lot, it can save space to call a function instead of the same thing over and over. It looks cleaner too.

@GPI

Yeah that does make more sense for compaction and definitely is better then my function, but it might scare new people away :p

Thanks for the comments!

P#135419 2023-10-04 22:18 ( Edited 2023-10-04 22:19)
1

@AntiBrain But that's what I mean, it seems like

X = GET_PIXEL(20,40)

is longer than

X = PGET(20,40)

Not token-wise obviously, but character-wise. But GET_PIXEL just calls PGET with the same params, so it seems like there's no benefit unless I'm missing something.

P#135422 2023-10-04 22:56
1

Good observation, @2bitchuck ! You are correct on that one! It may not save on chars, but it will save you tokens, although not that many. It also looks a lot cleaner if you are using PGET a lot for color detection, pixel math, ECT.

Get pixel and get mtile are kinda redundant because they only use one line on code, but the other two make more sense.

Look at @GPI's comment above for an actually good PGET function.

You could also shorten GET_PIXEL to something like GPX to save more space. I just wrote it as get pixel so that people know what it does and I am not coping right now

P#135423 2023-10-04 23:02 ( Edited 2023-10-04 23:12)
1

\> It may not save on chars, but it will save you tokens, although not that many.

I'm sorry to keep coming back, I feel like I'm a complete dunce here & definitely missing something, but in my desktop PICO-8, using X = PGET(20,40) and X = GET_PIXEL(20,40) both cost 6 tokens. So it seems like there's no benefit to not just using PGET directly.

Sorry, I'll stop now!

P#135424 2023-10-04 23:29

@2bitchuck don't worry about being annoying! You pose a great argument!

The function only really saves you tokens if you have lines and lines of PGETs. If you shorten GET_PIXEL() to just GPX(), you save much more space per PGET, but only if you have multiple PGETs.

Since the function only uses 43 chars ONCE, and GPX is 1 char smaller then PGET, if you manage to use the function 43 or more times, for every use after 43, you save 1 additional char per use.

If that doesn't make sense, then I'll rephrase it when I wake up because it is really late where I am :p

P#135433 2023-10-05 03:37
2

I don't think you're missing anything @2bitchuck.

@AntiBrain, I think you might be confusing characters and tokens. GET_TOKEN, PGET and GPX all have a different number of characters—9, 4 and 3 respectively—but they're all only one token. Using GPX instead of PGET may indeed save you characters in the long run but it won't save tokens which is what you said originally. Although, in fairness, it's still a bit confusing because GET_PIXEL, which is the function in the actual post, would save neither characters nor tokens.

I think what you're getting at here is that you're creating an alias for PGET because you find GET_PIXEL or GPX more semantically meaningful than PGET and thus easier for yourself to read/write/remember what it does? It doesn't add any additional functionality but better names can really help readability. I do that kind of thing all the time.

P#135452 2023-10-05 12:50
3

Sorry, I did mean chars and not tokens in my last comment. I was writing these comments on the bus and I was really stressed out and not rereading them, which I should of been doing. You are correct, they both use the same amount of tokens- infact, my function uses more because of the whole function loop. That kind of makes the whole thing redundant, but my reason for writing them was indeed not to save space, but to clean up code and make it more readable and not look like spaghetti. Sorry for confusing you 2bitchuck, I was wrong. Maybe it was bad that I didn't eat breakfast or drink water all day. (God what is wrong with me).

Thank you for the explanation jasondeleat! You've successfully disassembled the loops the hamster in my brain was running through at Mach 5.

And really, the same argument could be made for every function up there besides WAIT(), Because none of them really save space. To be fair, I wrongly wrote them here on my phone and forgot to test them when I got home, so take everything I say about compression here with a gram of salt. I'll mees around with them later today if I have time, and if I find one that actually is good, I'll update this post.

Sorry for being annoying @2bitchuck, and thank you for the explanation @jasondelaat.

P#135458 2023-10-05 13:58 ( Edited 2023-10-05 14:04)
1

@AntiBrain no worries at all, thanks for taking the time to post these! I always love seeing how other devs in the community approach things.

P#135459 2023-10-05 14:03

[Please log in to post a comment]