Frictional Games Forum (read-only)
Couple of Questions - 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: Couple of Questions (/thread-8993.html)



Couple of Questions - DRedshot - 07-06-2011

OK, i have a couple of questions,
1. in my map there is a part where i am froze to the spot, while a few visual things happen, after the visuals are over, a few script areas are activated (AddEntityCollideCallback). If One of these areas are activated whilst i am inside it, will the alState be 1? or will it be undefined untill i leave and reenter it?

2. how do i convert an integer into a string and vica versa? eg
Code:
void OnStart()
{
           for(int i=0, i<10, i++)
          {
           AddEntityCollideCallback("Player , i  , Collide , False , 1);
          }
AddLocalVarInt("Number" , 0);
}
void Collide(string &in asParent , string &in asChild , int &in alState)
{
SetLocalVarInt("Number" , asChild);
}
in this code i is an integer not a string, so it wont work in the AddEntityCollideCallback, also, asChild is not an integer, so it wont work in the SetLocalVarInt, help?



RE: Couple of Questions - MrBigzy - 07-07-2011

Er, this code would just set more integers, not create a string. Is there any reason why you would want to do that conversion? Are you trying to suffix strings for multiple callbacks?

Also for your first question, I'm pretty sure the boundaries of the area are the only thing that trigger the state and not the area itself. I could be wrong though; you would have to do some testing if you need to find out. Doing a debug might give you a message telling you whether you entered it or not.


RE: Couple of Questions - DRedshot - 07-07-2011

Yeah, basically, my script has 9 areas, named simply 1 to 9, and if im in one of these areas whilst looking away from an entity, named entity1 and entity2, it spawns a new entity, either entity1_(1 to 9) or entity2_(1 to 9) depending on which area im stood in. i hope that makes sense to you,

and thanks for answering my first question, i will try a debug message in a minute

EDIT: I managed to get it working fine, i declared int i as a string, and used LocalVarStrings instead of LocalVarInts


RE: Couple of Questions - Apjjm - 07-07-2011

Just for future reference, to you initial request for #2.

Integer to string conversion is easy, just append the integer onto the end of a string and angelscript will do the rest.
Code:
//Example usage

void example() {
int x = 50;
string s = "" + x;
}
String to UNSIGNED integer conversion, not so easy, need to build a parsing function. I've already built one though, so feel free to use it.
Code:
//Usage:
void example() {
string s = "a1b2c3d4";
int x = parseStringInt(s);
//X now equals 1234
}
//Helper functions written by me (Apjjm):
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(uint i=0; i<str.length(); i++)
     {
      int digit = getDigit(str[i]);
      output = (digit > -1)?(10*output+digit):(output);
     }
    return output;
}



RE: Couple of Questions - DRedshot - 07-07-2011

Thank You, that may come in handy at some point.