![]() |
StringSub failing in the background? - 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: StringSub failing in the background? (/thread-10484.html) |
StringSub failing in the background? - Your Computer - 09-26-2011 Assume the following code. Testing shows that "Passed1" gets printed to screen while "Passed2" doesn't. It does not fail to find the needle and it properly returns the index that it found the delimiter at. Why does it seem to end at StringSub()? Code: void ChangeMap(string &in map) RE: StringSub failing in the background? - Apjjm - 09-27-2011 Your array "ret" is empty from my quick glance, and you are also seem to be acessing the n+1th element of the array. I changed it's definition to: Code: string[] ret = {""}; Code: ret[ret.length() - 1] = StringSub(str, start, i); // Seems to be haulting Code: ret.resize(ret.length() + 1); Hope that helps ![]() Edit: Also, your int parsing function will crash the game if the assumed invariant is broken and a negative number or non-int is passed in. I think parsing character-by-character is probably going to be a better approach here than looping up to the number (it will certainly be more efficient as number size grows). I've been using this parse I wrote for a while now (refining it quite a bit since it's first appearance on the forums) - it may help you out a little. Code: //Helper function: Used to determine if the char "digit" represents a number RE: StringSub failing in the background? - Your Computer - 09-27-2011 Hmm, i was hoping it would resize automatically. I guess my knowledge of other scripting languages isn't entirely applicable here. Yeah, i know my StringToInt function will crash or continue indefinitely (until the system runs out of memory) if an inappropriate value is passed in, but i'm not worried about that for my simple purpose (if someone else, however, were to use it, then it may be problematic). I will try out your string conversion functions, though. (I was aiming more for PHP's way of string-to-int juggling for my purpose.) |