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
Custom function freezes the game.
Fearlessagent Offline
Junior Member

Posts: 12
Threads: 2
Joined: Jul 2012
Reputation: 1
#1
Custom function freezes the game.

So, in the custom story that I'm creating, I name things I need to interact with in the code quite precisely. Usually it takes the form of: ROOMNAME_ITEMNAME_TYPE

So for example, a note might be labled: lab_chemDiscovery_note

I wanted an easy function to extract the middle word, in the above case this would be "chemDiscovery". However, whenever the function is called, the game just locks up. Can anyone see what I might be doing wrong?

PHP Code: (Select All)
string getProperName(string &in var){
    
int chr 0;             //character number in string
    
string newString "";   //where the new string will be stored
    
string letter "";      //where the current letter being tested is stored
    
int l 0;               //how many underscores we've found
    
while(2){ //we can stop evaluating after finding 2 underscores
        //using StringSub(string,int,int) to return a partial string between two positions in the string.
        
letter StringSub(var, chrchr+1);
        
AddDebugMessage("Analyzing Letter: " letter,false);
        
//Only append a letter to the new string if its not an underscore and we've already found an underscore.
        
if ((letter != "_") && (== 1)){newString newString letter;}
        
//increase underscore count when finding one
        
else if (letter == "_"){l++;}
        
//increase character count 
        
chr++;
        
AddDebugMessage("New String: " newString,false);
    }
    return 
newString;


I'm thinking I should be able to call this function as:
PHP Code: (Select All)
getProperName("lab_chemDiscovery_note"); 
or even through passing a callback variable to it (the intention).
(This post was last modified: 07-07-2012, 08:29 AM by Fearlessagent.)
07-07-2012, 04:59 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Custom function freezes the game.

If i'm interpreting everything correctly, l would never be greater than 2.

Tutorials: From Noob to Pro
07-07-2012, 05:42 AM
Website Find
Fearlessagent Offline
Junior Member

Posts: 12
Threads: 2
Joined: Jul 2012
Reputation: 1
#3
RE: Custom function freezes the game.

(07-07-2012, 05:42 AM)Your Computer Wrote: If i'm interpreting everything correctly, l would never be greater than 2.
Correct, the goal is to stop the while loop after 2 underscores in the string are found, then return the string value.
07-07-2012, 05:52 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: Custom function freezes the game.

Infinite loops halt the game. The only time the script increments l is when it finds an underscore and if the previous if statement evaluates to false. With a syntax of ROOMNAME_ITEMNAME_TYPE, it is unlikely that either if statement would evaluate to true.

Tutorials: From Noob to Pro
07-07-2012, 05:57 AM
Website Find
Fearlessagent Offline
Junior Member

Posts: 12
Threads: 2
Joined: Jul 2012
Reputation: 1
#5
RE: Custom function freezes the game.

(07-07-2012, 05:57 AM)Your Computer Wrote: Infinite loops halt the game. The only time the script increments l is when it finds an underscore and if the previous if statement evaluates to false. With a syntax of ROOMNAME_ITEMNAME_TYPE, it is unlikely that either if statement would evaluate to true.
I kind of figured that's whats happening but I don't understand is why neither would evaluate to true. It would advance the character number regardless if the conditionals evaluated, until it hits an underscore. Then it would increase l by one and every letter after that would be appended to newString until it hits the last underscore. Thats the intention anyways, did I miss something?
07-07-2012, 06:07 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: Custom function freezes the game.

I did a test run, and i got the following output with "Text_Text_Text":

Analyzing Letter: T
New String:
Analyzing Letter: ex
New String:
Analyzing Letter: xt_
New String:
Analyzing Letter: t_Te
New String:
Analyzing Letter: _Text
New String:
Analyzing Letter: Text_T
New String:
Analyzing Letter: ext_Tex
New String:
Analyzing Letter: xt_Text
New String:
Analyzing Letter: t_Text
New String:
Analyzing Letter: _Text
New String:
Analyzing Letter: Text
New String:
Analyzing Letter: ext
New String:
Analyzing Letter: xt
New String:
Analyzing Letter: t
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
... (ad infinitum)

It is on an infinite loop, and as you can see letter never equals "_", so the issue is in the incrementing chr variable. Instead of adding 1, just put simply 1 -- that is, for StringSub.

I'm going to go to sleep now.

Tutorials: From Noob to Pro
(This post was last modified: 07-07-2012, 07:50 AM by Your Computer.)
07-07-2012, 07:44 AM
Website Find
Fearlessagent Offline
Junior Member

Posts: 12
Threads: 2
Joined: Jul 2012
Reputation: 1
#7
RE: Custom function freezes the game.

(07-07-2012, 07:44 AM)Your Computer Wrote: I did a test run, and i got the following output with "Text_Text_Text":

Analyzing Letter: T
New String:
Analyzing Letter: ex
New String:
Analyzing Letter: xt_
New String:
Analyzing Letter: t_Te
New String:
Analyzing Letter: _Text
New String:
Analyzing Letter: Text_T
New String:
Analyzing Letter: ext_Tex
New String:
Analyzing Letter: xt_Text
New String:
Analyzing Letter: t_Text
New String:
Analyzing Letter: _Text
New String:
Analyzing Letter: Text
New String:
Analyzing Letter: ext
New String:
Analyzing Letter: xt
New String:
Analyzing Letter: t
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
Analyzing Letter:
New String:
... (ad infinitum)

It is on an infinite loop, and as you can see letter never equals "_", so the issue is in the incrementing chr variable. Instead of adding 1, just put simply 1 -- that is, for StringSub.

I'm going to go to sleep now.
Man, I was never able to get the debug messages, my game just froze up...Thanks for your help. I completely forgot that the last argument in StringSub was the number of characters to read and not another character position. Ah well, just had one of those derp moments I suppose. Big Grin
07-07-2012, 08:29 AM
Find




Users browsing this thread: 2 Guest(s)