asar icon indicating copy to clipboard operation
asar copied to clipboard

convert decimal variable to hex

Open gizaha opened this issue 10 months ago • 4 comments

I have many folders, numbered 1,2,3,7,8,9,A,C,11,12 (hexadecimal numbers). I made a loop in asar to check each folder contents* one by one. The index value in loop is decimal so i cannot check the hexadecimal lettered folders, It would help something !letter #= hex(!index).

Long story short, i want to know which folders exist and which are not (for example 4,5,6 are missing)

  • using getfilestatus() to a fixed file existing in each folder

gizaha avatar Jan 25 '25 16:01 gizaha

I guess this is sort of similar to what was proposed in https://github.com/RPGHacker/asar/issues/183 - some way to convert numbers to hex literals.

Definitely worth doing in some form. Still not sure what the best approach is. Ideally, I'd like something that's flexible enough to also support other types of formatting in the future, but without polluting syntax in a way that could confuse Asar too much.

Honestly, I'd kinda like for Asar to support some kind of format strings. Maybe also as a future replacement for our current print mechanism?

RPGHacker avatar Jan 25 '25 17:01 RPGHacker

imo the most sane approach would be to make math support strings properly, then we can make the print-specific hex/dec/bin functions available in regular math too, and you could do !thing #= hex(whatever) (which is actually the exact syntax gizaha suggested)

trillllian avatar Jan 25 '25 17:01 trillllian

I found a workaround: I include a big file i create with autohotkey. The file contents are: !dec2hex_0 = 0 !dec2hex_1 = 1 !dec2hex_2 = 2 !dec2hex_3 = 3 !dec2hex_4 = 4 !dec2hex_5 = 5 !dec2hex_6 = 6 !dec2hex_7 = 7 !dec2hex_8 = 8 !dec2hex_9 = 9 !dec2hex_10 = A !dec2hex_11 = B !dec2hex_12 = C !dec2hex_13 = D !dec2hex_14 = E !dec2hex_15 = F !dec2hex_16 = 10 !dec2hex_17 = 11 !dec2hex_18 = 12

etc

so in asar when i want to convert i use !hex_converted := !{dec2hex_!{decimal}}

gizaha avatar Jan 25 '25 18:01 gizaha

implemented this, !thing #= hex(!number) should work in asar 2.0

trillllian avatar Mar 05 '25 13:03 trillllian