Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

selection past multiple status

Newbie Spellweaver
Joined
Jul 18, 2012
Messages
22
Reaction score
1
** assume that this npc script works **

PHP:
if (status == 0) {
cm.sendGetNumber("type in the id of an item you want");
cm.dispose();
} else if (status == 1) {
if (selection != blocked) {
cm.sendNext("are you sure you want #v" + selection + "# as your new item?");
} else {
cm.sendOk("this item is blocked.");
cm.dispose();
}
} else if (status == 3) {
cm.gainItem(selection, 1);
cm.dispose();
}

once i get to the third status, i feel as if the npc forgets what the selection was, thus giving me an error. am i supposed to add a variable somewhere or is there another way to do this?
** and once again, i just typed up part of it real quick, i already know that it works up until the third status which is where i'm supposed to receive my item
thxxxxxx.
 
Newbie Spellweaver
Joined
Nov 27, 2009
Messages
94
Reaction score
58
Yes, you need to store it in another variable declared at the top of your script.
This is because the status, selection, and mode all change every time action is called. Essentially, every time your status increases, there will be a new value for selection, and if you want to save the selection across multiple statuses, then you need to store it in a global script variable (which won't change until you stop talking to the npc).
 
Upvote 0
Newbie Spellweaver
Joined
Jan 31, 2014
Messages
23
Reaction score
11
add
itemid = selection;

after
} else if (status == 1) {

and change
cm.gainItem(selection, 1);

to
cm.gainItem(itemid);
 
Upvote 0
Newbie Spellweaver
Joined
Jul 18, 2012
Messages
22
Reaction score
1
thanks for both of your guys' reply, but when i try to add "var selection = itemid;" or "var itemid = selection;" at the top of the script (under the variable blocked, status and selected), i get an error: "selection/itemid is not defined." and when i try what you suggested, naive, i get some gainItem and getEquipById errors.

not able to be on the comp right not, but do variables always need to result in numbers/arrays? or am i able to do something like "" and get the result i need?

thanks once again.
 
Upvote 0
Custom Title Activated
Loyal Member
Joined
Aug 21, 2009
Messages
1,149
Reaction score
598
You don't assign the value in the top, you just declare the variable, so it's accessible in a global level, maintaining its value.

You declare it on top

PHP:
var itemid;

And you store the value whenever you need to, in your example, it should go after "status == 1" if statement.

PHP:
itemid = selection;

Then in the last status, you don't use "selection", because this variable changes each time "action" is called based on the NPC dialogs.

So you use the stored itemid to use properly the "gainItem" method:

PHP:
gainItem(itemid, 1);

-------------------EDIT-----------------------

As you asked about variables, variables can hold any type of data in JavaScript, pretty versatile.

You can hold integers:

PHP:
var lol = 1;

booleans:

PHP:
var lol = true;

string:

PHP:
var lol = "LOL";

floats:

PHP:
var lol = 1.9;

nulls:

PHP:
var lol = null;

functions:

PHP:
var lol = function lulz() { alert("lol"); };

arrays:

PHP:
var lol = ["hi", "lulz"];

maps (Or Objects):

PHP:
var lol = {hi : "lol", lulz : 999999999};

And so on...
 
Last edited:
Upvote 0
Back
Top