Jump to content

Question

Posted (edited)

I have some questions about temporary NPC variables.

Lets say I use .@r to store a variable in a NPC would that variable exist only within that NPC?

Now lets say, I have something like...

main {
.@r = 0;
call somefunc;
}
somefunc() {
 .@r = 2;
}

will .@r exist within 2 namespaces? namely main and somefunc or just the npc's namespace?

Also,

Is there any problems with nested switches? Anything to watch out for?

switch(select("1","2","3")) {
 case 1:
   switch(select("2","3")) {
  case 1:
	 ....
  case 2:
	 .....
   }
  case 2:
 switch(selec...
 ....

  ......
}

Edited by kotsumu

1 answer to this question

Recommended Posts

Posted

If it can help

-    script    var    -1,{

   function inside_func { // own namespace
       // .@b: 0
       set .@c, 5;
   } // <- clean .@c

   OnInit:
       set .@a, 5;
       end; // <- clean .@a


   OnEvent: // Custom event
       // .@a: 0
       set .@b, 3;
       inside_func();
       // .@c: 0
       // .@b: 3
       goto OnTest;

   OnTest: // goto keep variables
       // .@b: 3
       set .@c, 8;
       callsub OnTest2;
       // .@b: 3
       // .@c: 8
       // .@d: 0
       end; // clean .@b, .@c

   OnTest2:
       // .@b: 0
       // .@c: 0
       set .@d, 5;
       return; // <- clean .@d

}

.@var are limited to their namespaces and not copy to their inside function/callsub.

But you can modify them in a function using getarg():

-    script    var    -1,{

   function double {
       set getarg(0), getarg(0) * 2;
   }

   OnInit:
       set .@b, 10;
       double(.@;
       // .@b: 20
}

No problem with switch in switch.

You can even do function in function without problem :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...