Jump to content
  • 0

NPC Variables


kotsumu

Question


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   1
  • Joined:  05/31/12
  • Last Seen:  

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
Link to comment
Share on other sites

1 answer to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

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 :)

Link to comment
Share on other sites

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.

×
×
  • Create New...