]> Chaos Git - vn/vndc.git/commitdiff
Support for if statements with variables as rvalues, and fix because lookahead was...
authorchaoskagami <chaos.kagami@gmail.com>
Mon, 25 Aug 2014 03:26:15 +0000 (23:26 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Mon, 25 Aug 2014 03:26:15 +0000 (23:26 -0400)
Format.vndc.txt
bin/vndc.x86_64 [new file with mode: 0755]
vndc/include/Funcs.hpp
vndc/src/Parse.cpp
vndc/src/op_if.cpp

index be01bc1af9f8a58442ce939c84980213723841b2..a8228a82a438da3207fc0d9b62b5d29670578324 100644 (file)
@@ -22,7 +22,7 @@ Contents.
        13m. text
        14n. debug commands
                14n1. help
-               14n2. stop
+               14n2. resume
                14n3. quit
                14n4. save
        15o. Save format
@@ -116,17 +116,18 @@ Note that I am a bit smarter than vnds here. if and fi
 CAN be embedded. So this is valid:
 
        if selected == 2
-       if previous >= 5
-       text 'You win!'
-       fi
-       if previous <= 5
-       text 'You lose!'
-       fi
+               if previous >= 5
+                       text 'You win!'
+               fi
+               if previous <= 5
+                       text 'You lose!'
+               fi
        fi
 
 The behavior of VNDS would be to 'if previous <= 5' on
 failure of selected == 2 This is really not proper:
-I keep an if-count instead of an in-if value.
+vnds just jumps. I keep an if-count instead of
+an in-if bool value.
 
 = 6f. ================================================
 
@@ -147,10 +148,11 @@ jump transfers control to another script file:
 
 My implementation provides an extra form of jump:
 
-       jump script line
+       jump script [line]
 
 Which goes directly to line in the file. This
-is utilized for saving.
+is utilized for saving. As such, you can't
+turn off that extension. Period.
 
 = 8h. ================================================
 
@@ -184,7 +186,8 @@ position specified.
 
 setvar and gsetvar are used to set variables. gsetvar
 specifically sets the 'global' state, that is, common
-to all saves.
+to all saves. In my implementation - that is moot.
+Thus, gsetvar just calls setvar.
 
        [g]setvar var mod value
 
@@ -204,7 +207,15 @@ vnds, but typically at the beginning.
 
        setvar ~ ~
 
-Which means reset all vars.
+Which means reset all vars. This ignores globals -
+e.g. prefixed with a lowercase 'g'.
+
+As well, my extension provides the ability to set
+a variable to another variable.
+
+       [g]setvar var op var2
+
+Again, this only works in extensions mode.
 
 = 12l. ===============================================
 
@@ -240,12 +251,14 @@ I don't know why, but there are:
 I've implemented a few extensions that help generally
 with NVL games.
 
-       ---                     - At the beginning of a line,
+       ---                             - At the beginning of a line,
                                          clears before text output.
-       "                               - More on this once finished.
-                                         Will stop any previous sfx
-                                         if encountered. 'smart'
-                                         voice stop.
+       "                               - In the sound function
+                                         if lookahead finds a text
+                                         with quotes, it's assumed
+                                         that sound is a voice and
+                                         linked to the text. AKA
+                                         smart voice stopping.
 
 = 14n. ===============================================
 
@@ -258,9 +271,9 @@ start it from a console. Send it a SIGINT (^C).
 The console should now prompt you with this;
        [scr command] $
 
-You can enter any command above; I recommend against
-entering choice, since it can't possibly work in
-this mode. if may also not work as expected.
+You can enter any command above; Some won't work
+right. choice, if, and jump probably won't work
+properly.
 
 No commands run in this state will advance the
 program, but flags set will affect it.
@@ -271,9 +284,9 @@ help will print everything available.
 
 = 14n2. ==============================================
 
-stop will disable debugging and kill the console.
-You can SIGINT again at any point to come back
-to the debug state.
+resume (renamed from stop) will disable debugging
+and kill the console. You can SIGINT again at any
+point to come back to the debug state.
 
 = 14n3. ==============================================
 
diff --git a/bin/vndc.x86_64 b/bin/vndc.x86_64
new file mode 100755 (executable)
index 0000000..bbf3d63
Binary files /dev/null and b/bin/vndc.x86_64 differ
index 3a08b262fe9a05f165d9fac95c98fa57f1c6bc8b..4683a0eb4b6de6168cc3e9f62b56b63846eee0dc 100644 (file)
@@ -24,7 +24,7 @@ void op_cleartext();
 void op_delay(int* frames);
 void op_fi();
 void op_gsetvar(char* var, int *modifier, char *value);
-void op_if(char* var, int* op, int* val);
+void op_if(char* left, int* op, char* right);
 void op_music(char* file);
 void op_random(char* var, int* low, int* high);
 void op_setimg(char* file, int* x, int* y);
index e46e09dbedccf23c580bb904fa2ed04a061140ce..880c9780edfe6ff4fb98e3ccf137968333c1ec24 100644 (file)
@@ -117,8 +117,7 @@ void ParseCmd(char* line) {
                else if(!strcmp(tokens[2], ">="))
                        value_1 = 5;
 
-               sscanf(tokens[3], "%d", &value_2);
-               op_if(tokens[1], &value_1, &value_2);
+               op_if(tokens[1], &value_1, tokens[3]);
        }
        else if(!strcmp(tokens[0], "fi"))
                op_fi();
@@ -165,7 +164,7 @@ void ParseShell() {
 
                if(!strcmp(buffer, "help") || strlen(buffer) < 1) {
                        printf("%s\n", "Commands available:");
-                       printf("\t%s\t\t\t%s\n", "(debug) stop", "Stops debug mode");
+                       printf("\t%s\t\t\t%s\n", "(debug) resume", "Stops debug mode");
                        printf("\t%s\t\t\t%s\n", "(debug) quit", "Quits game");
                        printf("\t%s\t\t%s\n", "(debug) save [file]", "Saves immediately to file");
                        printf("\t%s\t%s\n", "setvar [var] [mod] [val]", "Set save flag");
@@ -189,7 +188,7 @@ void ParseShell() {
                        GetData()->ctx->SetQuit();
                        DebugContinue = false;
                }
-               else if (!strcmp(buffer, "stop")) {
+               else if (!strcmp(buffer, "resume")) {
                        printf("[debug] Exiting debug shell and resuming.\n");
                        DebugContinue = false;
                        GetData()->wait_input = true;
@@ -234,6 +233,12 @@ void Parse() {
                        line_copy[i] = '\0';
        }
 
+       // The next line is null, because the file is finished.
+       if(feof(GetData()->accessScriptHandle) && strlen(GetData()->next_line) == 0) {
+               // We've reached EOF. Jump back and return.
+               op_jump(GetData()->main_scr[0], NULL, true);
+       }
+
        GetData()->next_line = (char*)calloc(sizeof(char), 400);
        fgets(GetData()->next_line, 400, GetData()->accessScriptHandle);
 
@@ -246,12 +251,6 @@ void Parse() {
 
        // Load the next line.
 
-       // The next line is null, because the file is finished.
-       if(feof(GetData()->accessScriptHandle) && strlen(GetData()->next_line) == 0) {
-               // We've reached EOF. Jump back and return.
-               op_jump(GetData()->main_scr[0], NULL, true);
-       }
-
        return;
 }
 
index 2114d2b38b1c32fa7897b226a5ed6d72244cc429..1bca33f57da1092c9a49735c11a317def0b0381e 100644 (file)
@@ -9,40 +9,48 @@
  * ('<=':0 '<':1 '==':2 '!=':3 '>': '>=':5)
  */
 
-void op_if(char* var, int* op, int* val) {
+void op_if(char* left, int* op, char* right) {
        if (GetData()->if_fail != 0) {
                GetData()->if_fail += 1;
                return;
        }
 
-       int var_val = GetData()->s_flags[0][std::string(var)];
+       int r_val = 0, ret = 0;
+       
+       ret = sscanf(right, "%d", &r_val);
+
+       if(ret == 0 && GetData()->vndc_enabled) { // This is a var name. We couldn't scan a number.
+               r_val = GetData()->s_flags[0][std::string(right)];
+       }
+
+       int l_val = GetData()->s_flags[0][std::string(left)];
 
        //printf("op_if(%s, %d, %d)\n", var, op[0], val[0]);
        //printf("GetData()->s_flags[0][%s] = %d\n", var, GetData()->s_flags[0][std::string(var)]);
 
        switch (op[0]) {
                case 0:
-                       if ( !(var_val <= val[0]) )
+                       if ( !(l_val <= r_val) )
                                GetData()->if_fail += 1;
                        break;
                case 1:
-                       if ( !(var_val < val[0]) )
+                       if ( !(l_val < r_val) )
                                GetData()->if_fail += 1;
                        break;
                case 2:
-                       if ( !(var_val == val[0]) )
+                       if ( !(l_val == r_val) )
                                GetData()->if_fail += 1;
                        break;
                case 3:
-                       if ( !(var_val != val[0]) )
+                       if ( !(l_val != r_val) )
                                GetData()->if_fail += 1;
                        break;
                case 4:
-                       if ( !(var_val > val[0]) )
+                       if ( !(l_val > r_val) )
                                GetData()->if_fail += 1;
                        break;
                case 5:
-                       if ( !(var_val >= val[0]) )
+                       if ( !(l_val >= r_val) )
                                GetData()->if_fail += 1;
                        break;
        }