mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
createentity command: Actually have p1/p2/p3/p4 defaults
Since createentity() started accepting p1/p2/p3/p4 arguments, it now unconditionally passes in whatever arguments were present there previously, when there weren't any before. This can lead to unexpected behavior when selectively using and then omitting p1/p2/p3/p4 arguments. Also, plenty of existing levels already only use the 5-argument version of createentity(). And createcrewman() can take up to 6 arguments at once. It's not far-fetched that an existing level could createentity() right after doing a 6-argument createcrewman(), which would lead to a different behavior than in 2.2 and previous. So instead, instead of checking if `words[index]` is an empty string (it only sets the string to be empty if there are enough argument separators on the line), ACTUALLY check if it's empty. I've added a static array (no need for it to be exported) that keeps track of this. createentity() now checks for that instead of `words`.
This commit is contained in:
parent
87ec35eb45
commit
63a487d20d
2 changed files with 17 additions and 7 deletions
|
@ -38,6 +38,8 @@ void scriptclass::clearcustom(void)
|
|||
customscripts.clear();
|
||||
}
|
||||
|
||||
static bool argexists[NUM_SCRIPT_ARGS];
|
||||
|
||||
void scriptclass::tokenize( const std::string& t )
|
||||
{
|
||||
j = 0;
|
||||
|
@ -71,9 +73,15 @@ void scriptclass::tokenize( const std::string& t )
|
|||
}
|
||||
}
|
||||
|
||||
if (tempword != "" && j < (int) SDL_arraysize(words))
|
||||
SDL_zeroa(argexists);
|
||||
|
||||
if (j < (int) NUM_SCRIPT_ARGS)
|
||||
{
|
||||
words[j] = tempword;
|
||||
argexists[j] = tempword != "";
|
||||
if (argexists[j])
|
||||
{
|
||||
words[j] = tempword;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -756,10 +764,10 @@ void scriptclass::run(void)
|
|||
std::string word7 = words[7];
|
||||
std::string word8 = words[8];
|
||||
std::string word9 = words[9];
|
||||
if (words[6] == "") words[6] = "0";
|
||||
if (words[7] == "") words[7] = "0";
|
||||
if (words[8] == "") words[8] = "320";
|
||||
if (words[9] == "") words[9] = "240";
|
||||
if (!argexists[6]) words[6] = "0";
|
||||
if (!argexists[7]) words[7] = "0";
|
||||
if (!argexists[8]) words[8] = "320";
|
||||
if (!argexists[9]) words[9] = "240";
|
||||
obj.createentity(
|
||||
ss_toi(words[1]),
|
||||
ss_toi(words[2]),
|
||||
|
|
|
@ -15,6 +15,8 @@ struct Script
|
|||
std::vector<std::string> contents;
|
||||
};
|
||||
|
||||
#define NUM_SCRIPT_ARGS 40
|
||||
|
||||
class scriptclass
|
||||
{
|
||||
public:
|
||||
|
@ -47,7 +49,7 @@ public:
|
|||
|
||||
//Script contents
|
||||
std::vector<std::string> commands;
|
||||
std::string words[40];
|
||||
std::string words[NUM_SCRIPT_ARGS];
|
||||
std::vector<std::string> txt;
|
||||
std::string scriptname;
|
||||
int position;
|
||||
|
|
Loading…
Reference in a new issue