c4_angel Posted December 14, 2017 Posted December 14, 2017 Hello! Some int values are stored like a string in 2da files, e.g. UNSUABLE in KITLIST.2da(in another word, cannot use a SET after READ_2DA_ENTRY). Is there any way to make it work? Thank you! Quote
Jarno Mikkola Posted December 14, 2017 Posted December 14, 2017 Well, you don't read it as an integer, but as a string, and then threat it as one. Quote
CamDawg Posted December 14, 2017 Posted December 14, 2017 One of the absolute laziest ways you could work around this would be something like OUTER_SPRINT string_thats_actually_an_int 0x40000000 <<<<<<<< ./inlined.tpa OUTER_SET new_var_thats_an_int = %string_thats_actually_an_int% >>>>>>>> COPY ~./inlined.tpa~ ~./inlined.tpa~ EVALUATE_BUFFER REINCLUDE ~./inlined.tpa~ COPY_EXISTING ~sw1h01.itm~ ~override~ WRITE_LONG 0x08 new_var_thats_an_int Someone not as lazy as I am could come up with a nifty macro to do it. Quote
argent77 Posted December 14, 2017 Posted December 14, 2017 Or use the less known SPRINTF command: OUTER_TEXT_SPRINT myString ~0xff~ OUTER_PATCH ~~ BEGIN // currently only available as patch command SPRINTF myDecNum ~%d~ (~%myString%~) // hex number as string -> decimal number SET myDecNum = myDecNum / 2 // myDecNum is treated as number SPRINTF myHexNum ~%x~ (~%myDecNum%~) // decimal number -> hex number as string END PRINT ~myString = %myString%, myDecNum = %myDecNum%, myHexNum = %myHexNum%~ // Output: myString = 0xff, myDecNum = 127, myHexNum = 0x7f Quote
Wisp Posted December 14, 2017 Posted December 14, 2017 (edited) Jarno wins. The only distinction TP2 makes between stings and integers are which strings are not integers after coercion. This works fine: OUTER_SPRINT myvar "123" OUTER_SET myothervar = myvar COPY_EXISTING sw1h01.itm override WRITE_LONG NAME1 myvar I hate to pick nits but... CamDawg, %string_thats_actually_an_int% is exactly equivalent to "string_thats_actually_an_int". On their own, percentage signs are string delimiters. Inside strings, they delimit variables, but only inside strings. Edited December 14, 2017 by Wisp Quote
CamDawg Posted December 14, 2017 Posted December 14, 2017 I hate to pick nits but... CamDawg, %string_thats_actually_an_int% is exactly equivalent to "string_thats_actually_an_int". On their own, percentage signs are string delimiters. Inside strings, they delimit variables, but only inside strings. No worries, always something to learn. After all Fixpack is but a collection of fixes wrapped in picked nits. Quote
Ardanis Posted December 15, 2017 Posted December 15, 2017 (edited) I hate to pick nits but... CamDawg, %string_thats_actually_an_int% is exactly equivalent to "string_thats_actually_an_int". On their own, percentage signs are string delimiters. Inside strings, they delimit variables, but only inside strings. I could swear I'v seen cases when it wouldn't evaluate properly without percentages, sometimes double percentages. Edited December 15, 2017 by Ardanis Quote
Jarno Mikkola Posted December 15, 2017 Posted December 15, 2017 (edited) I could swear I'v seen cases when it wouldn't evaluate properly without percentages, sometimes double percentages.Are you sure you weren't placing a string, into another ? As in, you place a variable that can change according to what game it's modified(BGT, Tutu etc). For example all the items they have, as the Tutu has a _ -before nearly all of the .itm file names. Which happens to be %tutu_var% in code, or whatever. Edited December 15, 2017 by Jarno Mikkola Quote
Gwendolyne Posted December 16, 2017 Posted December 16, 2017 (edited) I hate to pick nits but... CamDawg, %string_thats_actually_an_int% is exactly equivalent to "string_thats_actually_an_int". On their own, percentage signs are string delimiters. Inside strings, they delimit variables, but only inside strings. I could swear I'v seen cases when it wouldn't evaluate properly without percentages, sometimes double percentages. +1 but I can't explain why and in which cases... Edited December 16, 2017 by Gwendolyne Quote
argent77 Posted December 16, 2017 Posted December 16, 2017 I hate to pick nits but... CamDawg, %string_thats_actually_an_int% is exactly equivalent to "string_thats_actually_an_int". On their own, percentage signs are string delimiters. Inside strings, they delimit variables, but only inside strings. I could swear I'v seen cases when it wouldn't evaluate properly without percentages, sometimes double percentages. +1 but I can't explain why and in which cases... Double percentages are needed to evaluate content of evaluated variable names, e.g. OUTER_TEXT_SPRINT myVar ~Hello World!~ OUTER_TEXT_SPRINT varName ~myVar~ OUTER_TEXT_SPRINT result EVAL ~%%varName%%~ // result = ~Hello World!~ Quote
Miloch Posted December 16, 2017 Posted December 16, 2017 Jarno wins. The only distinction TP2 makes between stings and integers are which strings are not integers after coercion. This is one of the few things I knew. The only surprising thing is that the point goes to Jarno... Quote
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.