Jump to content


Photo

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


11 replies to this topic

#1 c4_angel

c4_angel
  • Members
  • 33 posts
  • Gender:Male
  • Location:Shanghai, China

Posted 14 December 2017 - 08:06 AM

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!



#2 Jarno Mikkola

Jarno Mikkola

    The Imp

  • Modders
  • 6578 posts
  • Gender:Male
  • Location:The town where the dead haven't keeled over, yet. In Finland.

Posted 14 December 2017 - 08:54 AM

Well, you don't read it as an integer, but as a string, and then threat it as one.


Welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand.
Here's how to install all the ... mods you ever really could want to Infinity Engine games. I removed the stable word from there as Roxanne began to add BS mods that are likely to break compatibility from the BWS.

#3 CamDawg

CamDawg

    Just a simple country Hyper-Chicken

  • Gibberling Poobah
  • 9442 posts
  • Gender:Not Telling

Posted 14 December 2017 - 09:12 AM

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.


I came here with a simple dream: a dream of killing all humans. And this is how it must end? Who's the real seven billion ton robot monster here? Not I. Not... I.


#4 argent77

argent77
  • Modders
  • 783 posts
  • Gender:Male

Posted 14 December 2017 - 10:16 AM

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


#5 Wisp

Wisp
  • Modders
  • 1108 posts
  • Gender:Male

Posted 14 December 2017 - 11:00 AM

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, 14 December 2017 - 11:03 AM.


#6 CamDawg

CamDawg

    Just a simple country Hyper-Chicken

  • Gibberling Poobah
  • 9442 posts
  • Gender:Not Telling

Posted 14 December 2017 - 11:49 AM


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.

I came here with a simple dream: a dream of killing all humans. And this is how it must end? Who's the real seven billion ton robot monster here? Not I. Not... I.


#7 c4_angel

c4_angel
  • Members
  • 33 posts
  • Gender:Male
  • Location:Shanghai, China

Posted 15 December 2017 - 04:32 AM

Thanks to all of you.



#8 Ardanis

Ardanis

    A very GAR character

  • Modders
  • 2586 posts
  • Gender:Male
  • Location:Saint-Petersburg, Russia

Posted 15 December 2017 - 10:19 AM

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, 15 December 2017 - 10:19 AM.

Retired from modding.


#9 Jarno Mikkola

Jarno Mikkola

    The Imp

  • Modders
  • 6578 posts
  • Gender:Male
  • Location:The town where the dead haven't keeled over, yet. In Finland.

Posted 15 December 2017 - 10:35 AM

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, 15 December 2017 - 10:38 AM.

Welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand.
Here's how to install all the ... mods you ever really could want to Infinity Engine games. I removed the stable word from there as Roxanne began to add BS mods that are likely to break compatibility from the BWS.

#10 Gwendolyne

Gwendolyne
  • Members
  • 188 posts
  • Gender:Male
  • Location:France

Posted 16 December 2017 - 01:49 AM

 

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, 16 December 2017 - 01:50 AM.

CARPE DIEM...



In progress : Menace sur le Royaume de Diamant Éternel

#11 argent77

argent77
  • Modders
  • 783 posts
  • Gender:Male

Posted 16 December 2017 - 01:55 AM

 

 

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!~


#12 Miloch

Miloch

    Barbarian

  • Modders
  • 4793 posts
  • Gender:Male
  • Location:At Large

Posted 16 December 2017 - 05:22 AM

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...


Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it." -Terry Pratchett



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users