Shadowfied
Senior Member
Posts: 261
Threads: 34
Joined: Jul 2010
Reputation:
5
|
Need help understanding this
I'm messing around a bit with the entities from White Night just to try them out, particularly the lamps and lamp-switches, but I'm so confused.
I've inspected the White Night map and how the lamps and switches are placed and named etc and tried doing similar myself. It looks like in White Night, using this script:
void Lamp_Switcher(string &in asEntity, int alState)
{
if( alState == -1)
SetLampLit("swithcher_1_"+StringSub(asEntity,10,11), false, true);
if( alState == 1)
SetLampLit("swithcher_1_"+StringSub(asEntity,10,11), true, true);
}
Yeah using this script it seems that this is the only thing required and as long as the switchers and lamps are named correctly this is enough script. I tried doing the same, putting a switcher, naming it switcher_7 and a lamp (exactly same entity as in the place which I'm looking at in White Night) with the name switcher_1_7 and adding the "Lamp_Switcher" in the ConnectionStateChangeCallback box for the switch, but it doesn't work. If I just do it simple, removing the +StringSub parts etc it works, but then I'll have to make that script for every lamp and switch.
I don't understand what "+StringSub(asEntity,10,11) does..Especially "asEntity,10,11"....can anyone help me understand this?
Thanks in advance.
(This post was last modified: 01-20-2012, 11:57 AM by Shadowfied.)
|
|
01-20-2012, 10:06 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Need help understanding this
Technically, a string is generally a char array. In other words, "some text" is the same as {'s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't'}. Therefore a character in a string can be accessed by its index; starting from 0 if read from left to right, starting from -1 if read from right to left. The numbers you're providing in StringSub() is the starting index and the number of characters you want to include from that index. So, StringSub("some text", 4, 2) will return " t".
You do not want to go passed the size of the string itself, as this may crash the game. So try to avoid using string.length() for the third parameter. Also, do note that providing -1 for the third parameter will tell the function to stop at the end of the string. So, StringSub("some text", 4, -1) will return " text"; StringSub("some text", 4, -2) will return " tex"; and so on.
|
|
01-20-2012, 11:28 AM |
|
Shadowfied
Senior Member
Posts: 261
Threads: 34
Joined: Jul 2010
Reputation:
5
|
RE: Need help understanding this
(01-20-2012, 11:28 AM)Your Computer Wrote: Technically, a string is generally a char array. In other words, "some text" is the same as {'s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't'}. Therefore a character in a string can be accessed by its index; starting from 0 if read from left to right, starting from -1 if read from right to left. The numbers you're providing in StringSub() is the starting index and the number of characters you want to include from that index. So, StringSub("some text", 4, 2) will return " t".
You do not want to go passed the size of the string itself, as this may crash the game. So try to avoid using string.length() for the third parameter. Also, do note that providing -1 for the third parameter will tell the function to stop at the end of the string. So, StringSub("some text", 4, -1) will return " text"; StringSub("some text", 4, -2) will return " tex"; and so on. Okay thanks, that helped me understand it a little bit.
Do you know how to make the script work?
|
|
01-20-2012, 11:56 AM |
|
|