From 749a885d9afbe78de4fdf37e4c0928131d851f7a Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 21 Aug 2021 19:55:16 -0700 Subject: [PATCH] Actually finally fix createentity default args Third time's the charm. The fundamental problem with the previous attempts was that they ended up saying arguments existed due to stale `words` anyway. So to actually know if an argument exists or not, we need to assign to `argexists` _as_ we parse the line. And make sure to take care of that last argument too. Also I thoroughly tested this this time around. I'm done pulling my hair out over this. --- desktop_version/src/Script.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 7f2d9273..21d7bd59 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -46,12 +46,15 @@ void scriptclass::tokenize( const std::string& t ) std::string tempword; char currentletter; + SDL_zeroa(argexists); + for (size_t i = 0; i < t.length(); i++) { currentletter = t[i]; if (currentletter == '(' || currentletter == ')' || currentletter == ',') { words[j] = tempword; + argexists[j] = words[j] != ""; for (size_t ii = 0; ii < words[j].length(); ii++) { words[j][ii] = SDL_tolower(words[j][ii]); @@ -73,16 +76,14 @@ void scriptclass::tokenize( const std::string& t ) } } - if (tempword != "" && j < (int) SDL_arraysize(words)) + if (j < (int) SDL_arraysize(words)) { - words[j] = tempword; - } - - SDL_zeroa(argexists); - - for (size_t ii = 0; ii < NUM_SCRIPT_ARGS; ++ii) - { - argexists[ii] = words[ii] != ""; + const bool lastargexists = tempword != ""; + if (lastargexists) + { + words[j] = tempword; + } + argexists[j] = lastargexists; } }