Jump to content
  • 0

Loop variables


BTNX

Question


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

Hi all,

 

I'm a scripting noob and I have noobish question.

 

I've noticed that most of the loops that I see here uses a temporary NPC int variable.  Is there a reason why it seems like it is preferred? 

 

I'm currently writing a script that will triggers a loop via OnNPCKillEvent: that goes on to more blocks of script, functions and sql queries etc.

OnNPCKillEvent:
message strcharinfo(0),"Start script";
if(!getcharid(2)){ dispbottom "not in guild"; end;}//End when not in guild
for (set .@c, 0; .@c < getarraysize(.mvp_mobid); set .@c, .@c + 1){
	dispbottom "Xref mob ID";
	if (killedrid == .mvp_mobid[.@c]){ goto Kill_mvp;
	}else { dispbottom "killed monster not on MvP list"; end; }
} 
More scripts blah blah

Here's the array:

setarray .mvp_mobid[0],       1511,         1647,        1785,        1785,        1785,        1785;
setarray .mvp_town$[0],   "morroc","lighthalzen",    "rachel",    "rachel",     "veins",     "veins";
setarray .mvp_map$[0], "moc_pryd06",  "lhz_dun03", "ra_fild03", "ra_fild04", "ve_fild01", "ve_fild02";
setarray .mvp_points[0],         1,            2,           1,           1,           1,           1; 

 I would like to use:

.@c

as the index for:

.mvp_mobid[.@c]

Buuuuuut, I don't want the value of 

.@c

to change because another player triggers the loop and get my data all mixed up.

I could, in theory transerver the value to a more personal character variable:

set @index, .@c;

My question is, why do I not see people use temporary int character variable instead of temporary int NPC variable?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

".@"     - A scope variable.

           They are unique to the instance and scope. Each instance has its

           own scope that ends when the script ends.

Each player talking to the npc run an unique instance. 2 players talking to a npc don't share their scope variable. When a player stop talking the script end and the scope variable - attached the instance- are deleted from memory (no need to keep them in memory isn't it? otherwise it's a waste of memory).

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  55
  • Reputation:   3
  • Joined:  04/02/12
  • Last Seen:  

Thx, I didnt know that thats what that meant

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...