Frictional Games Forum (read-only)
[Help] String to Int conversion - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [Help] String to Int conversion (/thread-17129.html)



[Help] String to Int conversion - SPACoD - 07-20-2012

Hi, everyone, I got a problem, I don't know how to convert string to int.
I want to make a code locking mechanism which is shorter than the one I made before but I can't.

Here is the code:


if(Code[1][4] == 1)
{
string Entered = StringSub(asEntity, 12, 1);
PlayGuiSound("Click", 1);
Code[1][0] = Entered; <- This line gives an error that it can't implictly convert string& to int&
Code[1][4]++;
AddDebugMessage("Entered: " + Code[1][0], false);
}

So, the buttons are called in a range from Lock_Button_0 to Lock_Button_9.
Code[1][4] is the digit you're currently entering (in this case the first).
The string "Entered" extracts the number from the name of the button (the string is the number, so I want to convert it to an integer).
Code[1][0] is the number that is set when a corresponding button is pressed (can range from 0 to 9).
I am no expert on C++, but I know some tricks Wink

If someone knows how to do this I'd be very grateful.
Greetz, SPACoD


RE: [Help] String to Int conversion - Kreekakon - 07-20-2012

Couldn't you create an int value that reacts accordingly to whatever number is inputed instead of having to convert anything?

EDIT: Also, you posted this in the wrong section. It should be in development support.


RE: [Help] String to Int conversion - SPACoD - 07-20-2012

My old version is like that (it has 276 lines of code), I just wanted to make it shorter. I need to add an if check for every single button I press for all 4 digits to do what you said above (that's 40 checks).

Also, I saw some threads like my in this section so I put it here, sorry for the wrong one Sad


RE: [Help] String to Int conversion - Kreekakon - 07-20-2012

If you used a "for" type of script in there along with the "if" checks, you could make the if checks automated, requiring only four "if checks" in your case.

If you don't understand the concept of "for", I'll be more than happy to explain.


RE: [Help] String to Int conversion - Your Computer - 07-20-2012

http://www.frictionalgames.com/forum/post-87716.html#pid87716


RE: [Help] String to Int conversion - Kreekakon - 07-20-2012

Damn, Computer, you've got a really strong memory.


RE: [Help] String to Int conversion - Traggey - 07-20-2012

Duh, it's a computer.


RE: [Help] String to Int conversion - SPACoD - 07-20-2012

(07-20-2012, 11:19 AM)Kreekakon Wrote: If you used a "for" type of script in there along with the "if" checks, you could make the if checks automated, requiring only four "if checks" in your case.

If you don't understand the concept of "for", I'll be more than happy to explain.
Of course I know how to use for, used around my whole script file, but you know, I'm a bit special so I forget stuff like that xD
There is easy, hard and SPACoD way which is the easy way done hard

The post that Computer directed me to didn't really help, I used the parseStringUint function and it shows up this error

No matching signatures to '_ParseDigit(uint8&)'
and this one
No matching signatures to 'parseStringUint(string)'

This is what I did:


uint parseStringUInt(string &in asString)
{
uint output = 0;
for(uint i=0; i<asString.length(); i++) {
int digit = _ParseDigit(asString[i]);
output = (digit > -1)?(10*output+digit)Sadoutput); }
return output;
}

void EnterCode(string &in asEntity)
{
if(Code[1][4] == 1)
{
PlayGuiSound("Click", 1);
Code[1][0] = parseStringUint(StringSub(asEntity, 12, 1));
Code[1][4]++;
AddDebugMessage("Entered: " + Code[1][0], false);
}
The rest is untouched...