Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Help] String to Int conversion
SPACoD Offline
Junior Member

Posts: 13
Threads: 4
Joined: Jan 2012
Reputation: 0
#1
[Help] String to Int conversion

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
(This post was last modified: 07-20-2012, 10:19 AM by SPACoD.)
07-20-2012, 10:14 AM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#2
RE: [Help] String to Int conversion

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.
(This post was last modified: 07-20-2012, 10:43 AM by Kreekakon.)
07-20-2012, 10:41 AM
Find
SPACoD Offline
Junior Member

Posts: 13
Threads: 4
Joined: Jan 2012
Reputation: 0
#3
RE: [Help] String to Int conversion

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
07-20-2012, 11:15 AM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#4
RE: [Help] String to Int conversion

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.
07-20-2012, 11:19 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#5
RE: [Help] String to Int conversion

http://www.frictionalgames.com/forum/pos...l#pid87716

Tutorials: From Noob to Pro
07-20-2012, 11:30 AM
Website Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#6
RE: [Help] String to Int conversion

Damn, Computer, you've got a really strong memory.
07-20-2012, 11:32 AM
Find
Traggey Offline
is mildly amused

Posts: 3,257
Threads: 74
Joined: Feb 2012
Reputation: 185
#7
RE: [Help] String to Int conversion

Duh, it's a computer.
07-20-2012, 11:32 AM
Find
SPACoD Offline
Junior Member

Posts: 13
Threads: 4
Joined: Jan 2012
Reputation: 0
#8
RE: [Help] String to Int conversion

(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...
(This post was last modified: 07-20-2012, 12:51 PM by SPACoD.)
07-20-2012, 11:53 AM
Find




Users browsing this thread: 5 Guest(s)