Is there a javascript equivalent of mudlet's display(table) function? I'm trying to view a multidimensional array and print() only returns object Object instead of a read out of the values.
More specifically, I'm trying to view the gmcp table (that is, args.gmcp_args in the onGMCP function).
In a similar vein, when mudlet gets a gmcp packet it stores it all in a gmcp table I can go back to at any time. Does the html5 do this? If not can I make it do that?
Also...is there an html5 equivalent to isPrompt()? I see the block of text thing, but can I make something (such as an echo) fire after the next prompt or is pattern matching the prompt regex my best bet?
sys['areas'] = new Array(); sys['areas']['the Valley of Lodi'] = new Array(); sys['areas']['the Valley of Lodi']['targets'] = ["a juvenile wildcat", "an adult wildcat", "a wildcat servant", "a wildcat soldier", "a guard pig", "a portly gnome sentry", "a gnome sentry", "a skinny gnome sentry", "a deputy constable", "a lithe weasel", "a cave bat"];
[/spoiler]
Is this the best way to do this? (yay I went from wtf am i doing plz halp to how 2 do better???)
edit: jk new problem:
sys['areas'][the Valley of Lodi']['items'] = ["an empty tin flask", "a miner's pick"];
The ' in the miner's pick is making the colors freak out how fix Is there an escape character to make it realize it's part of the string? Like \ or % in lua?
You want the object literal syntax instead of arrays for most of those:
var sys = sys or {<br> vitals = {<br> bleeding = 0,<br> current = {<br> health = 0,<br> mana = 0,<br> endurance = 0,<br> willpower = 0<br> }<br> } <br>}
You can technically use arrays, but there's no reason to. If you use non-integer indexes it works because arrays are themselves objects in JavaScript, but you don't get any of the benefits of an Array if you're using it that way. If you're used to Mudlet, you just have tables which can be either dictionaries or arrays. In JavaScript that's equivalent to an object or an array, respectively.
In terms of accessing those, you can use either the dot or square bracket notations:
You can even mix and match if you really want to. If you have a dynamic key that's stored in a variable you need to use the square bracket notation:
var myKey = 'health';<br> sys.vitals.current[myKey] = 1000
For iterating, use for loops. For an object:
for(key in object) {<br> var value = object[key]<br> // do something<br> }
And for an array:
for(var i = 0, l = a.length; i < l; i++) {<br> var value = a[i];<br> }<br>
Okay next question...how to delete settings please
Selecting function and clicking remove button doesn't work, tried variations of right clicking, dragging to remove button, making sure I saved it first...stumped.
Thanks! I'm just making a thing that tells me when I enter a new area, and displays notes I might have set about that area if it's in my list of area notes. Like WTF R U DOING HERE UR GOING 2 DIE.
sys.areas = { 'the Valley of Lodi' : { level : '5-21', targets : { 'a juvenile wildcat', 'an adult wildcat', 'a wildcat servant', 'a wildcat soldier', 'a guard pig', 'a portly gnome sentry', 'a gnome sentry', 'a skinny gnome sentry', 'a deputy constable', 'a lithe weasel', 'a cave bat' }, items : { 'an empty tin flask', // 'a miner's pick', // 'the half-eaten corpse of a sheep', } }, 'the Land of Minia' : { level : '5-21', targets : { 'a juvenile wildcat', 'an adult wildcat', 'a wildcat servant', 'a wildcat soldier', 'a guard pig', 'a portly gnome sentry', 'a gnome sentry', 'a skinny gnome sentry', 'a deputy constable', 'a lithe weasel', 'a cave bat' }, items : { 'an empty tin flask', } }, };
print('workses') [/spoiler]
Which returns:
Error in Function [sys.init_areas]: SyntaxError: missing : after property id
And I'm guessing it's because I tried to list the items and targets and I need to do something like 0 = 'first target' and so on?
Okay, will I need to change the initial setting of possible_targets and possible_items to = [] as well? I don't know how echoing works either tbh, just print('string '+myVar) is all I know so far. Would like to learn how to use color echoes.
I should probably go to bed but now I'm all excited about learning also I found answers to like half the things I asked so let me recap more briefly the ones I didn't...
Are there any resources for quick html5 help, like mudlet has the mudlet clan in game?
Is there any way to move the gauges/avatar (rearranging windows won't let me move those two) or to remove the avatar?
Is there an escape character that will let me use 's in strings without it doing weird things?
And new questions cropping up...
I use stopwatches religiously in mudlet, is there an equivalent for the html5 or do I need to work with tempTimer type things?
In a similar vein, I really want to do something that tracks how long has passed since X and displays the time, is there an easier way to do this than what I'm thinking with stopwatches?
Sorry to be crazy wish post edit timer was longer thanks for patience!
edit: PS is there any way to make it save settings when you qq or...? Must not code tired will lose all settings.
Quick Resources: The forums are probably your best bet for now!
Gauges/Avatar: Not in the current version, it might make an appearance in the future.
Escape Char: Using a \ should escape a trailing character.
Stopwatches: We don't have anything like that built-in at the moment, you can use tempTimers or track start time and end time to calculate elapsed times though.
Save on QQ: This is all handled through the save button on the settings window currently!
RE: stopwatches, what I want to do with it is two things. First, in my mudlet system, I have a feature that resets and starts a stopwatch when I see that I don't have balance and my balance variable is true, because that's the point I lost balance at. When I regain balance, it checks the stopwatch time and tells me how long I had lost it for.
The other manner in which I use stopwatches is associated with all afflictions/defenses. When my system sends a command (like eat bloodroot) it resets and starts the stopwatch associated with the affliction it's trying to cure, and sets that affliction's state to 'waiting'. If the stopwatch reaches a certain amount of time (sys.delay() returns different times in aeon/retardation, with stupidity, and normally) it resets the affliction's state to 'afflicted' so it'll resend the command to cure it.
What would be the best way to do these two things in html5 client?
edit: For the second one, I think I could use a named timer and kill it whenever I need to reset it, my main concern with using tempTimer in mudlet was when I would cure something and then get afflicted again before delay expired and it would start freaking out.
New questions...accessing and using gmcp. I think I asked above, about a display(gmcp) equivalent. print() keeps showing me [object Object] instead of anything useful. It would be really helpful to be able to view the table, so I can see for example how to get the items or players in room, etc.
Is there and equivalent of return in javascript? I mean, if I want to break a fragment of script and tell it to stop running?
For example, if I have a function I run on gaining an affliction, but the affliction is aeon and I have the speed defense active, I would call my function to remove speed defense and then stop running the rest of the aff_gain (since I didn't actually gain aeon).
Javascript has return as well, it immediately stops the function. If you want to just exit a loop and continue with the rest of the function, use break.
@Adioro this might come in handy for you, I liked your aggressive development, i'm doing the same but on sister mud. Got stuck on some problems but I solved some of yours from before.
Can you teach me how you use spoiler tags in the forum. My forum kung fu is poor.
// example how I fetch the value of a array.
// add this to onLoad i advice.
var contain = function (arr, v) {
return arr.indexOf(v) > -1;
};
// test
alert(
contain(areas['the Valley of Lodi'].targets,
"a juvenile wildcat"));
// and yeah use [] in the array
Syntax for disabling your own function, alias, trigger or group.
// Example:
// var x = client.reflex_find_by_name('function', 'catch', true, false, 'ButterflyCatcher'); client.reflex_disable(x);
I found that I could run predefined functions (like Math.round) without using run_function, and in fact they wouldn't work within it. Only the functions I made did, does that help you @Mishgul?
No, the html5 puts everything inside the function because the script -is- the function. @Mishgul, try this:
[spoiler] if (flowerpot){
return true;
}; else {
return false;
};
[/spoiler]
I think the problem you're having has to do with able being a local variable? But I may be wrong. Either way, this will give you the same effect but with no error.
Comments
More specifically, I'm trying to view the gmcp table (that is, args.gmcp_args in the onGMCP function).
In a similar vein, when mudlet gets a gmcp packet it stores it all in a gmcp table I can go back to at any time. Does the html5 do this? If not can I make it do that?
var sys = sys or {<br> vitals = {<br> bleeding = 0,<br> current = {<br> health = 0,<br> mana = 0,<br> endurance = 0,<br> willpower = 0<br> }<br> } <br>}
You can technically use arrays, but there's no reason to. If you use non-integer indexes it works because arrays are themselves objects in JavaScript, but you don't get any of the benefits of an Array if you're using it that way. If you're used to Mudlet, you just have tables which can be either dictionaries or arrays. In JavaScript that's equivalent to an object or an array, respectively.
In terms of accessing those, you can use either the dot or square bracket notations:
sys.vitals.current.health = 1000<br> sys['vitals']['current']['health'] = 1000
You can even mix and match if you really want to. If you have a dynamic key that's stored in a variable you need to use the square bracket notation:
var myKey = 'health';<br> sys.vitals.current[myKey] = 1000
For iterating, use for loops. For an object:
for(key in object) {<br> var value = object[key]<br> // do something<br> }
And for an array:
for(var i = 0, l = a.length; i < l; i++) {<br> var value = a[i];<br> }<br>
Results of disembowel testing | Knight limb counter | GMCP AB files
:-S
JavaScript uses the colon (:) to separate key and value rather than the equals sign, so:
var sys = sys || {<br> vitals: {<br> bleeding: 0,<br> current: {<br> health: 0,<br> mana: 0<br> }<br> }<br>}
Results of disembowel testing | Knight limb counter | GMCP AB files
[spoiler]
sys.vitals : {
bleeding : 0,
current : {
health : 0,
mana : 0,
endurance : 0,
willpower : 0
},
max : {
health : 0,
mana : 0,
endurance : 0,
willpower : 0
},
percent : {
health : 0,
mana : 0,
endurance : 0,
willpower : 0
},
old : {
health : 0,
mana : 0,
endurance : 0,
willpower : 0
},
loss : {
health : 0,
mana : 0,
endurance : 0,
willpower : 0
},
};
print('omg works yay');
[/spoiler]
And it returns:
Error in Function [sys.init_vitals]:
SyntaxError: missing ; before statement
sys.vitals = {
bleeding: 0,
...
}
Results of disembowel testing | Knight limb counter | GMCP AB files
omg works yay
You say, "Yessssssssssss."
670h, 803m, 2250e, 2700w ex-
Selecting function and clicking remove button doesn't work, tried variations of right clicking, dragging to remove button, making sure I saved it first...stumped.
if sys.areas[sys.my.area] ~= nil then
do some stuff
end
Only in javascript. Not sure how! I know it's if (something something) {do some stuff};
if (sys.areas[sys.my.area] !== undefined) {
do some stuff
}
Results of disembowel testing | Knight limb counter | GMCP AB files
[spoiler]
sys.areas = {
'the Valley of Lodi' : {
level : '5-21',
targets : {
'a juvenile wildcat',
'an adult wildcat',
'a wildcat servant',
'a wildcat soldier',
'a guard pig',
'a portly gnome sentry',
'a gnome sentry',
'a skinny gnome sentry',
'a deputy constable',
'a lithe weasel',
'a cave bat'
},
items : {
'an empty tin flask',
// 'a miner's pick',
// 'the half-eaten corpse of a sheep',
}
},
'the Land of Minia' : {
level : '5-21',
targets : {
'a juvenile wildcat',
'an adult wildcat',
'a wildcat servant',
'a wildcat soldier',
'a guard pig',
'a portly gnome sentry',
'a gnome sentry',
'a skinny gnome sentry',
'a deputy constable',
'a lithe weasel',
'a cave bat'
},
items : {
'an empty tin flask',
}
},
};
print('workses')
[/spoiler]
Which returns:
Error in Function [sys.init_areas]:
SyntaxError: missing : after property id
And I'm guessing it's because I tried to list the items and targets and I need to do something like 0 = 'first target' and so on?
But anyways, I also have this:
[spoiler]
var area = args;
sys.my.area = area;
sys.possible_targets = {};
sys.possible_items = {};
if (sys.areas[sys.my.area] != undefined) {
sys.bashing.target_type = 'long';
sys.possible_targets = sys.areas[sys.my.area].targets;
print(' Level Range: '+sys.areas[sys.my.area].level);
print('Possible Targets:');
print('targets here...');
if (sys.areas[sys.my.area].items != undefined) {
sys.possible_items = sys.areas[sys.my.area].items
print('Gathering Items:');
print('items here...');
}
}
else {
print('Unknown Area.');
}
[/spoiler]
And on the italics parts I want to display the lists from that area. I assume this will be a for loop? But not quite sure how to implement.
On the other part, it would be a for loop. Not sure how echoing works in the HTML5 client though.
Results of disembowel testing | Knight limb counter | GMCP AB files
The other manner in which I use stopwatches is associated with all afflictions/defenses. When my system sends a command (like eat bloodroot) it resets and starts the stopwatch associated with the affliction it's trying to cure, and sets that affliction's state to 'waiting'. If the stopwatch reaches a certain amount of time (sys.delay() returns different times in aeon/retardation, with stupidity, and normally) it resets the affliction's state to 'afflicted' so it'll resend the command to cure it.
What would be the best way to do these two things in html5 client?
edit: For the second one, I think I could use a named timer and kill it whenever I need to reset it, my main concern with using tempTimer in mudlet was when I would cure something and then get afflicted again before delay expired and it would start freaking out.
For example, if I have a function I run on gaining an affliction, but the affliction is aeon and I have the speed defense active, I would call my function to remove speed defense and then stop running the rest of the aff_gain (since I didn't actually gain aeon).
Best way to do this?
-
One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important
// Example:
// var x = client.reflex_find_by_name('function', 'catch', true, false, 'ButterflyCatcher'); client.reflex_disable(x);
//client.reflex_enable(x);
//client.reflex_disable(x);
-- This one is also useful
// Syntax:
// reflex_find_by_name = function(type, name, case_sensitive, enabled_only, pkg)
@Asesino, just use this for spoilers:
[ spoiler]text[ /spoiler]
except without the spaces.
-
One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important
SyntaxError: Illegal return statement
-
One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important
-
One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important
[spoiler]
if (flowerpot){
else {
I think the problem you're having has to do with able being a local variable? But I may be wrong. Either way, this will give you the same effect but with no error.