Jump to content

How to convert a string-like int variable to a real int variable?


c4_angel

Recommended Posts

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.

Link to comment

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
Link to comment

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 by Wisp
Link to comment

 

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.
Link to comment

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 by Ardanis
Link to comment

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 by Jarno Mikkola
Link to comment

 

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 by Gwendolyne
Link to comment

 

 

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!~
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...