HTML5 Client Questions and Such

1235715

Comments

  • 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?

  • Adioro said:
    Learning learning learning...an hour and a half later, I've come up with this:

    [spoiler]
    var sys = new Array();

    sys['vitals'] = new Array();
    sys['vitals']['bleeding'] = 0;
    sys['vitals']['current'] = new Array();
    sys['vitals']['current']['health'] = 0;
    sys['vitals']['current']['mana'] = 0;
    sys['vitals']['current']['endurance'] = 0;
    sys['vitals']['current']['willpower'] = 0;
    sys['vitals']['max'] = new Array();
    sys['vitals']['max']['health'] = 0;
    sys['vitals']['max']['mana'] = 0;
    sys['vitals']['max']['endurance'] = 0;
    sys['vitals']['max']['willpower'] = 0;
    sys['vitals']['percent'] = new Array();
    sys['vitals']['percent']['health'] = 0;
    sys['vitals']['percent']['mana'] = 0;
    sys['vitals']['percent']['endurance'] = 0;
    sys['vitals']['percent']['willpower'] = 0;
    sys['vitals']['old'] = new Array();
    sys['vitals']['old']['health'] = 0;
    sys['vitals']['old']['mana'] = 0;
    sys['vitals']['old']['endurance'] = 0;
    sys['vitals']['old']['willpower'] = 0;
    sys['vitals']['loss'] = new Array();
    sys['vitals']['loss']['health'] = 0;
    sys['vitals']['loss']['mana'] = 0;
    sys['vitals']['loss']['endurance'] = 0;
    sys['vitals']['loss']['willpower'] = 0;

    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>&nbsp;&nbsp;&nbsp; vitals = {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bleeding = 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current = {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; health = 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mana = 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endurance = 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; willpower = 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; } <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:

    &nbsp;&nbsp;&nbsp; sys.vitals.current.health = 1000<br>&nbsp;&nbsp;&nbsp; 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:

    &nbsp;&nbsp;&nbsp; var myKey = 'health';<br>&nbsp;&nbsp;&nbsp; sys.vitals.current[myKey] = 1000

    For iterating, use for loops. For an object:

    &nbsp;&nbsp;&nbsp; for(key in object) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var value = object[key]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // do something<br>&nbsp;&nbsp;&nbsp; }

    And for an array:

    &nbsp;&nbsp;&nbsp; for(var i = 0, l = a.length; i < l; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var value = a[i];<br>&nbsp;&nbsp;&nbsp; }<br>
  • Thanks! That looks suspiciously like mudlet tables.
    :-S

  • edited April 2014
    Ugh, that's because that -is- the Lua table syntax. This is what I get for posting when I'd just woken up.

    JavaScript uses the colon (:) to separate key and value rather than the equals sign, so:

    var sys = sys || {<br>&nbsp;&nbsp;&nbsp; vitals: {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bleeding: 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current: {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; health: 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mana: 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}
  • Okay, I had puzzled that out with the help of The Google after the first error, heh. I'm to here so far:

    [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


  • Ah ok. If you're setting a new property on an object that already exists, you'd still use the =:

    sys.vitals = {
        bleeding: 0,
        ...
    }
  • 670h, 803m, 2250e, 2700w ex-

    omg works yay

    You say, "Yessssssssssss."

    670h, 803m, 2250e, 2700w ex-


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


  • Trying to do this:

    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};


  • Assuming sys.areas and sys.my.area both exist, you should be able to just do:

    if (sys.areas[sys.my.area] !== undefined) {
        do some stuff
    }
  • 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.

  • Okay, now I have this:

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


  • Ok, targets and items should actually be arrays, since they're just lists of strings. So change the { to [ and } to ].

    On the other part, it would be a for loop. Not sure how echoing works in the HTML5 client though.
  • 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.

  • TectonTecton The Garden of the Gods
    Adioro said:
    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!

  • edited April 2014
    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.

  • Is there a way to force a prompt? IE after I print() something, to make it look cleaner?

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

    Best way to do this?


  • 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.
  • MishgulMishgul Trondheim, Norway
    are there any alternatives to run_function("myFunction");. It doesn't seem to be working at the moment either.

    -

    One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important

    As drawn by Shayde
    hic locus est ubi mors gaudet succurrere vitae
  • edited April 2014
    Mishgul said:
    are there any alternatives to run_function("myFunction");. It doesn't seem to be working at the moment either.
    syntax
    run_function(name, args, pkg) // can use ALL on pkg

    // example
    // name = defEnergetic
    // pkg = Defensive
    run_function("defEnergetic", "", 'Defensive') 
    // example advanced
    run_function("onGMCP", {"gmcp_method":gmcp_method, "gmcp_args":gmcp_args}, 'ALL'); <-- advanced

    @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);


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


    I had to dig in the .js code to dig some of this up.

    -- Colours print
    print("QUACK MODE OFF", '#FF8080')}
  • edited April 2014
    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?

    @Asesino, just use this for spoilers:

    [ spoiler]text[ /spoiler]

    except without the spaces.

  • MishgulMishgul Trondheim, Norway
    somewhat. Still having a few issues. Reading a lot of documentation.

    -

    One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important

    As drawn by Shayde
    hic locus est ubi mors gaudet succurrere vitae
  • MishgulMishgul Trondheim, Norway
    okay so I created a function and put this code in:

    --

    var able;

    if (flowerpot) 
    {
        able = true;
    } else {
        able = false;
    };           

    return able;

    --


    I get this error

    Error in Function [systemAble]:
    SyntaxError: Illegal return statement

    -

    One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important

    As drawn by Shayde
    hic locus est ubi mors gaudet succurrere vitae
  • I believe if your return is not inside a function.
    image
  • MishgulMishgul Trondheim, Norway
    how do i put it "inside" the function?

    -

    One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important

    As drawn by Shayde
    hic locus est ubi mors gaudet succurrere vitae
  • edited April 2014
    function systemAble(){
    var able;
       if (flowerpot){
          able = true;
       } else {
          able = false;
       };           
    return able;
    }

    The return is inside the function, and also, flowerpot should be defined. 

    But in this particular case, I would rather do:

    function systemAble(){
    return new Boolean(flowerpot).valueOf();
    }


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


Sign In or Register to comment.