Jump to content

Photo

Help With Combining Global Scripts

Global Script Combining Help Global Scripts

  • Please log in to reply
6 replies to this topic

#1 TheLink

TheLink

    An octorok under a duck?!?!

  • Members
  • Gender:Male
  • Location:UK

Posted 08 January 2017 - 08:40 AM

Hello. I have just recently put all of my scripts together successfully and managed to compile them. However, after doing so I realised that I need to combine my global scripts, I tried doing that, and then adding it to my main script, but it didn't work that well.

I got this when trying to compile:

pass 1: parsing

line 2356: syntax error, unexpected lbrace, on token {

fatal error p00: can't open or parse input file

 

original script: https://drive.google...SXJoa1QtTUltcnc

my attempt at combining global scripts: https://drive.google...NGZiX3VDWFNCeDQ

 

after trying to combine the global scripts, I copied what I got and pasted it two lines underneath the original script, then tried compiling it.

 

final script: https://drive.google...QTJBNE5uRmU3VUE

 

I do have some programming knowledge, and understand what a syntax error it (which is the error I got), however I don't know the syntax of zscript because I haven't programmed with it before. So i don't know what an unexpecteed lbrace is. If anyone can help explain what the error means, or more importantly how I can fix it, I would be very grateful. Thanks for your time!



#2 judasrising

judasrising

    I play guitar

  • Members
  • Gender:Male
  • Location:Sweden but born in Finland

Posted 08 January 2017 - 09:00 AM

Hello. I have just recently put all of my scripts together successfully and managed to compile them. However, after doing so I realised that I need to combine my global scripts, I tried doing that, and then adding it to my main script, but it didn't work that well.

I got this when trying to compile:

pass 1: parsing

line 2356: syntax error, unexpected lbrace, on token {

fatal error p00: can't open or parse input file

 

original script: https://drive.google...SXJoa1QtTUltcnc

my attempt at combining global scripts: https://drive.google...NGZiX3VDWFNCeDQ

 

after trying to combine the global scripts, I copied what I got and pasted it two lines underneath the original script, then tried compiling it.

 

final script: https://drive.google...QTJBNE5uRmU3VUE

 

I do have some programming knowledge, and understand what a syntax error it (which is the error I got), however I don't know the syntax of zscript because I haven't programmed with it before. So i don't know what an unexpecteed lbrace is. If anyone can help explain what the error means, or more importantly how I can fix it, I would be very grateful. Thanks for your time!

Try this edit, but beware i cant test it.

------------------------------------------------------------------------------------------------------------------

global script slot2 {
 void run() {
  // Initialize variables used to listen on screen changes
  int curscreen = -1;
 
  while (true){ 
   // Keep track of screen changes
   // Run a Barrier script on every screen change
   if (Game->GetCurScreen() != curscreen){ 
    curscreen = Game->GetCurScreen();
    Barriers_NewScreen();
 
   Waitframe();
}
}
}
}


#3 ZoriaRPG

ZoriaRPG

    ZC Contributor & Wiki Editor

  • Members
  • Gender:Unspecified
  • Location:Prydon Academy

Posted 08 January 2017 - 09:02 AM

Unexprected left curly brace '{'.
 
Most often when you forgot a semi-colon a the end of an instruction, a closing right brace ')' at the end of a function call, or you have a scoping issue, as is the case here.
 
Do you normally use LISP, or something?

Gaaaah...so many open lbraces...
 
{
    void run()
    {
        //Setup variables for ice combos.
        Setup_IceCombos();

        //Variable that stores Game->GetCurScreen() the previous frame.
        int oldscreen = Game->GetCurScreen();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

{
    void run()
    {
        //Initialize variables used to store Link's strating position on Screen Init.
        int olddmap = Game->GetCurDMap();
        int oldscreen = Game->GetCurDMapScreen();
        int startx = Link->X;
        int starty = Link->Y;
        int startdir = Link->Dir;
 
        //Clear global variables used by Bottomless pits.
        Falling = 0;
        Warping = false;
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 void run() {
  // Initialize variables used to listen on screen changes
  int curscreen = -1;

  while (true) {
   // Keep track of screen

You have three open run function calls there, each one with a preceding lbrace... You may only call run() once per script; and it functions similarly to main(), on a per-script basis. What you want, is this:
 
//file scope

global script All
{ 
    //Script scope
    void run()
    {
        //run() function scope
        //Setup variables for ice combos.
        Setup_IceCombos();

        //Initialize variables used to store Link's strating position on Screen Init.
        int olddmap = Game->GetCurDMap();
        int oldscreen = Game->GetCurDMapScreen();
        int startx = Link->X;
        int starty = Link->Y;
        int startdir = Link->Dir;
    
        //Clear global variables used by Bottomless pits.
        Falling = 0;
        Warping = false;

        // Initialize variables used to listen on screen changes
        int curscreen = -1;
        
        RefreshBottles();
        
        while (true)
        {
            //while loop scope 
            // Keep track of screen changes
            // Run a Barrier script on every screen change
            if (Game->GetCurScreen() != curscreen)
            {
                curscreen = Game->GetCurScreen();
                Barriers_NewScreen();
            }

            EmptyBottleGlobal();
            Waitdraw();
            if(Link->Action != LA_SCROLLING)
            {
                Update_HoleLava(startx, starty, olddmap, oldscreen, startdir);
                if(Link->Z==0 && !Falling && (oldscreen != Game->GetCurDMapScreen() || olddmap != Game->GetCurDMap()))
                {
                    olddmap = Game->GetCurDMap();
                    oldscreen = Game->GetCurDMapScreen();
                    startx = Link->X;
                    starty = Link->Y;
                    startdir = Link->Dir;
                }
            }


            Update_IceCombos(oldscreen);
            oldscreen = Game->GetCurScreen();

            BombsScreenShake(); //put this line into your global loop (to combine this script with your global script)
            Waitframe();
        } //end of while loop scope
    } //end of run() function scope
} //end of script scope

//resume of file scope
 

I don't even want to think about if you set up Tamamo's HoleLava thing properly. I posted a pre-combined, nested version of the script a while back, to solve this kind of issue, and there are newer scripts that might perform better.

Edited by ZoriaRPG, 08 January 2017 - 09:11 AM.


#4 TheLink

TheLink

    An octorok under a duck?!?!

  • Members
  • Gender:Male
  • Location:UK

Posted 08 January 2017 - 09:07 AM

Thanks a lot, it works now!

 

Also what is LISP?

 

 

Do you normally use LISP, or something?


#5 ZoriaRPG

ZoriaRPG

    ZC Contributor & Wiki Editor

  • Members
  • Gender:Unspecified
  • Location:Prydon Academy

Posted 08 January 2017 - 09:19 AM

Thanks a lot, it works now!
 
Also what is LISP?


https://en.wikipedia...mming_language)

Take careful note of my code comments on the scoping of that script, so that in the future, you can reference, and understand each scoped level. Inside the while scope, there are also statements, where instructions are at the statement scope.

There are some minor scoping issues i ZScript that you may need to learn as well, notably that all variables declared in any function scope remain in use until that scope closes, even if they are declared at a lower nest.

void foo(){
    if ( x == 1 ) { 
        int n;
    }
}
While variable n is only available to the statement scope, it is still in use until foo() exits. :(

This is extremely important, because run() is a fumction.

ffc script a{
    void run(){
        int v = 0; int w = 6; //These are available at this scope, or lower. 
        for ( int q = 10; q > 0; q-- ) { //q is only available at this scope, 
                                         //but it never gives up its stack space. 
            if ( w % 3 == 0 ) v++;
            w--;
        }
    }
}
Here, declaring 'q' inside the for loop uses up stack space as if the variable was declared at the scope of run(), despite it only being available to the for statement.

This can become a whopper of a problem, if you do it repeatedly, as you may only have 255* variables in operation at one time. *Limit further reduced by other stack usage.

I suggest learing early to declare variables at the run scope, and reusing them; and moreover, to use arrays instead of simple vars.

ffc script foo{
    void run(){
        int q[256];
        q[1] = 6;
        for ( q[0] = 10; q[0] > 0; q[0]-- ){
              if ( q[1] % 3 == 0 ) q[2]++;
        }
    }
}
Compared to the last script, this one uses a total of one register for its variables, as opposed to three. Further, because the declaration is not at the scrope of the loop, but at the function scope, it isn't a wasted register.

If you need any help with arrays, I made a how-to document for them about a year ago that you might want to read.

Conserving stack space is probably the most fundamental principal in ZScript.

I hope that this also further helped demonstrate the concept of scope for you.

Edited by ZoriaRPG, 08 January 2017 - 09:33 AM.


#6 TheLink

TheLink

    An octorok under a duck?!?!

  • Members
  • Gender:Male
  • Location:UK

Posted 08 January 2017 - 09:37 AM

Thanks for the help, and I don't use LISP, at the moment I only know python.



#7 ZoriaRPG

ZoriaRPG

    ZC Contributor & Wiki Editor

  • Members
  • Gender:Unspecified
  • Location:Prydon Academy

Posted 08 January 2017 - 10:13 AM

Thanks for the help, and I don't use LISP, at the moment I only know python.


I asked, because LISP sort of looks like that. An endless sea of open braces, with dynamic scoping.

Aye, Python doesn;t use curly spaces, so soping certainly looks different. :)

In ZScript, as in C, scope is purely defined:

In instruction blocks, by open and closed curly braces, '{' and '}',
In statements, or function calls/declarations, by open and closed parens '(' and ')' and
In array index nests, by open and closed braces '[', and ']'.

Thus...
 
//! file scope: global values and global functions are at this scope.

int GlobalValueN; //This variable is available to all scripts, and functions. 
int ptrs[4096]; //global array. Always available. use these, and not simple vars:

//ZScript may only have 255 vars in use, and this cap is reduced by function calls
//and other things, but you may have 4095 arrays in use, each with a maximum 
//size of 214747, which gives you an effective 879,603,712 variables, instead of 255. 

//! file scope breaks here, and we enter the script scope of ffc script foo:

ffc script foo{ //! left curly brace (LBRACE) opens the scope
    void run() { //! function declaration, with left and right parens for its params, and a LBRACE to open the scope
        //Array declarations:
        int arr[16]; //declare an array with a size of 16 indices
        int arrB[10]; //declare a second array, size of 10.
        int arrC[2]; //third array, size of 2. 
        //These are available to this script, and any scope at the level of run(), or lower...
        //  **AND** they can be made available to other scripts, because they have array pointers. 
        bool run = false; //Only available to this script. 
        arr[0] = arrbB; //store the pointer for arrB in arrC[0];
        arr[1] = 100; 
        arrC[0] = arr; //store the pointer for arr in arrC[0].
        arrC[1] = arrB; //and store the pointer to arrB.
        arrC[0[0]] = 10; //! Nested braces for array usage. 
        ptrs[0] = arrC; //Now we can also reference any of these arrays globally, until they become invalid, because we stored their pointers globally. 
        //Note that this does not follow 2D array syntax from C.
        while ( --arrC[0[0]] >= 0 && ( arr[1] > 0 || run == true ) ) { //! new scope
                                //A statement with its condition 
                                //in a nested statement series, with nests handled by parens. 
                                //Priority with parens works as with standard maths. 
             arr[1] = DoSomething(arrC[0]); //! Call a function, and put the param inside the parens. 
             if ( arr[1] <= 0 ) { //! This is another scope, this time under while()
                 run = true;
             } //! end scope of the if statement
             if ( run === true ) DoOtherThing(); //! Another scope, under while, without
                                                 // curly braces. The parens define the scope here. 
             Waitframe(); 
        }
    }
    // This function is at the SCRIPT scope, and thus local to the script. 
    // This is similar to how a class function works in C, and you can call 
    // it externally  with a dereference to the script.
    //it needs scope resolution if you call it externally. 
    int DoSomething(int v){ //declare a function with one input. 
         return v + 100; 
    } //! end this the while loop scope
}//! end script scope

//! resume file scope

//! This function is at a file (global) scope, and available to everything without needing scope resolution. 
void DoSomethingElse(int val){
                    //use the dot for scope resolution to call a function that is at the scope of a script. 
    GlobalValueN = foo.DoSomething(val); //set the global value by first referencing the 
                                         //function local to the script foo 'DoSomething()'
    int aptr = ptrs[0]; //Grab the pointer to make referencing it easier, and to avoid the parser complaining. 
    if ( aptr != 0 ) { //new scope level inside this function to ensure that the pointer is valid
        aptr[1[5]] val - 100; //This stores the value into the array arrB[5] in the script 'foo'.
    }
}
I hope that is a useful demonstration, and not merely a confusing mess. I intend to give this sort of thing a good few pages in the revised ZScript docs, with yet more pages of working samples of this sort of thing, in use.

Edited by ZoriaRPG, 08 January 2017 - 10:20 AM.




Also tagged with one or more of these keywords: Global Script, Combining, Help, Global, Scripts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users