Windows Studio already had built-in dec2hex functionality all along (for Windows at least, lol)

TheouAegis

Member
Except for debugging purposes or displaying values (e.g., colors) in hexadecimal to your program's users, there is pretty much no reason to ever use a dec2hex() or dectohex() script to convert a number to a string of a hexadecimal number. For those times when you do need or want to convert an integer to a hexadecimal string, Game Maker Studio already had a function for that:

ptr(val)

It's not intended to be used as a dec2hex script, but on Windows it does that (and Android, kinda). Just surround it with string() and you can treat it as any other string.

show_debug_message(ptr(255));
show_debug_message(string_char_at(string(ptr(255),8));

Edit: See below for warnings on use with other operating systems. I'm curious what this does on Mac.
 
Last edited:

FrostyCat

Redemption Seeker
It's not intended to be used as a dec2hex script precisely because its to-string behaviour isn't formally standardized.

Try your code on HTML5 or Android for a change, and you'll see what I mean by that.
 

TheouAegis

Member
Even just is_string() would have sufficed there. I thought it was odd it returned what was essentially a string, but not a string. So on HTML5/Android, ptr(255) would still be 255? Or an error?
 

FrostyCat

Redemption Seeker
Using runtime 2.2.5.378, I got 255 on HTML5 and 0xff on Android.

With this much variance in the output, I cannot accept this as a functional replacement for dec2hex() scripts.
 

TheouAegis

Member
Ok. Good to know. Thanks for testing it.

I mean, you could still work with the Android one. :p That HTML5 one puts a damper on things, though.
 
Last edited:
Top