The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



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
StringSub failing in the background?
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#1
StringSub failing in the background?

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()?

void ChangeMap(string &in map)
    {
        string[] split = StringSplit(map, ":");

        if (split.length() > 1)
        {
            AddDebugMessage(split[0], false);
            AddDebugMessage(split[1], false);
//            ChangeMap(split[0], split[1], "", "");
        }

        else AddDebugMessage("String array length less than 1", false);
    }

void OnEnter()
    {
        AddTimer("creed_of_amnesia.map:StartMenu", 3, "ChangeMap");
    }

int StringFindFirst(string &in heystack, string &in needle, int start)
    {
        if (StringContains(heystack, needle))
        {
            if (start < 0)
                start = 0;

            for (int i = start; i < heystack.length(); ++i)
            {
                if (StringSub(heystack, i, 1) == needle)
                {
                    AddDebugMessage("Found needle: "+needle, false);
                    return i;
                }
            }
        }

        else AddDebugMessage("No needle in heystack", false);

        AddDebugMessage("Couldn't find needle in heystack", false);
        return -1;
    }

string[] StringSplit(string &in str, string &in delimiter)
    {
        string[] ret;

        int start = 0;
        int i = StringFindFirst(str, delimiter, start);

        string str_i = i;
        str_i += " "+str.length();
        AddDebugMessage(str_i, false);

        while (i != -1)
        {
            if (str.length() < start
            || str.length() < i)
                break;

            AddDebugMessage("Passed1", false);
            ret[ret.length()] = StringSub(str, start, i); // Seems to be haulting
            AddDebugMessage("Passed2", false);

            start = i+1;
            i = StringFindFirst(str, delimiter, start);
        }

        return ret;
    }

int StringToInt(string &in str)
    {
        if (str.length() > 0)
        {
            int i = 0;
            string chk_str = i;

            while (str != chk_str)
            {
                ++i;
                chk_str = i;
            }

            return i;
        }

        return 0;
    }

Tutorials: From Noob to Pro
(This post was last modified: 09-27-2011, 12:39 AM by Your Computer.)
09-26-2011, 11:29 PM
Website Find


Messages In This Thread
StringSub failing in the background? - by Your Computer - 09-26-2011, 11:29 PM



Users browsing this thread: 1 Guest(s)