BTNX Posted February 28, 2015 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Share Posted February 28, 2015 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? Quote Link to comment Share on other sites More sharing options...
Capuche Posted February 28, 2015 Group: Developer Topic Count: 10 Topics Per Day: 0.00 Content Count: 2407 Reputation: 616 Joined: 07/05/12 Last Seen: March 20 Share Posted February 28, 2015 ".@" - 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). Quote Link to comment Share on other sites More sharing options...
BTNX Posted March 1, 2015 Group: Members Topic Count: 13 Topics Per Day: 0.00 Content Count: 55 Reputation: 3 Joined: 04/02/12 Last Seen: October 22, 2022 Author Share Posted March 1, 2015 Thx, I didnt know that thats what that meant Quote Link to comment Share on other sites More sharing options...
Question
BTNX
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.
Here's the array:
I would like to use:
as the index for:
Buuuuuut, I don't want the value of
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:
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.