![]() |
Custom function freezes the game. - 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: Custom function freezes the game. (/thread-16801.html) |
Custom function freezes the game. - Fearlessagent - 07-07-2012 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: string getProperName(string &in var){ I'm thinking I should be able to call this function as: PHP Code: getProperName("lab_chemDiscovery_note"); RE: Custom function freezes the game. - Your Computer - 07-07-2012 If i'm interpreting everything correctly, l would never be greater than 2. RE: Custom function freezes the game. - Fearlessagent - 07-07-2012 (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. RE: Custom function freezes the game. - Your Computer - 07-07-2012 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. RE: Custom function freezes the game. - Fearlessagent - 07-07-2012 (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? RE: Custom function freezes the game. - Your Computer - 07-07-2012 I did a test run, and i got the following output with "Text_Text_Text": Code: Analyzing Letter: T 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. RE: Custom function freezes the game. - Fearlessagent - 07-07-2012 (07-07-2012, 07:44 AM)Your Computer Wrote: I did a test run, and i got the following output with "Text_Text_Text":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. ![]() |