Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support


Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help understanding this
Author Message
Shadowfied Offline
Senior Member

Posts: 261
Joined: Jul 2010
Reputation: 5
Post: #1
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.

Current - Castle Darkuan
Other - F*cked Map
(This post was last modified: 01-20-2012 11:57 AM by Shadowfied.)
01-20-2012 10:06 AM
Find all posts by this user Quote this message in a reply
Your Computer Offline
SCAN ME!

Posts: 3,475
Joined: Jul 2011
Reputation: 234
Post: #2
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.

Tutorials: From Noob to Pro
01-20-2012 11:28 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Shadowfied Offline
Senior Member

Posts: 261
Joined: Jul 2010
Reputation: 5
Post: #3
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?

Current - Castle Darkuan
Other - F*cked Map
01-20-2012 11:56 AM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)