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
How to convert a string to an integer?
cook Offline
Member

Posts: 103
Threads: 6
Joined: Apr 2011
Reputation: 0
#1
How to convert a string to an integer?

As the title says, making a script that returns the Entity's 6th letter(which is a number) that is being interacted with to a string using SetLocalVarString("bigman", StringSub(asEntity, 5, 1));, but that didn't work. Couldn't use LocalVarInt bigman either. I believe I need a way to convert it to an integer to make use of it like so SetEntityActive("crowbar_joint_"+"bigman", true);

It's for a crowbar that works on all doors script so I don't have to copy like 30 lines of code 9 times, if anyone could think of a easier way to do it please tell me.

Also, while I am here, what is the actual definition of a signature?
(This post was last modified: 06-11-2011, 05:42 AM by cook.)
06-11-2011, 05:26 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: How to convert a string to an integer?

I read something on the FricGames blog that mentioned AngelScript being a strong-typed language. Try this:

for(int x=1;x<2;x++) if(StringSub(asEntity, 5, 1) == x) SetLocalVarString("bigman", x);

This line doesn't try to convert the string into an integer it just tries to make a relation between the two. Change SetLocalVarString to SetLocalVarInt if that's what you need. Not sure if it will work but it's a guess Smile Good luck.

(This post was last modified: 06-11-2011, 07:11 AM by palistov.)
06-11-2011, 07:09 AM
Find
MrBigzy Offline
Senior Member

Posts: 616
Threads: 18
Joined: Mar 2011
Reputation: 8
#3
RE: How to convert a string to an integer?

You would use it like this:

SetEntityActive("crowbar_joint_"+bigman, true);

With bigman as LocalInt of course.

Edit: Oh, for multiple areas. Just do:

for(int i=1;i<10;i++) SetEntityActive("crowbar_joint_"+i, true);
(This post was last modified: 06-11-2011, 07:58 AM by MrBigzy.)
06-11-2011, 07:41 AM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#4
RE: How to convert a string to an integer?

I wrote a function some time back that parses out all the digits from a string and converts them into one integer. E.g: "1a2b3c" would become 123.

int getDigit(uint8 digit) {
    int d = digit-48; //48 is ASCII code for 0
    return ((d >= 0)&&(d<=9)) ? d : -1;
}
int parseStringINT(string str) {
    int output = 0;
    for(int i=0; i<str.length(); i++)
     {
      int digit = getDigit(str[i]);
      if(digit > -1) output = 10*output+digit;  
     }
    return output;
}
(This post was last modified: 06-11-2011, 03:00 PM by Apjjm.)
06-11-2011, 02:57 PM
Find
cook Offline
Member

Posts: 103
Threads: 6
Joined: Apr 2011
Reputation: 0
#5
RE: How to convert a string to an integer?

Thanks a lot guys
06-11-2011, 03:17 PM
Find




Users browsing this thread: 1 Guest(s)