Squiffy arrays

Hey, here's a cute trick I started using in my "Pathfinder" game. This creates arrays using javascript functions, but they are in squiffy variables and can last across the duration of your game.

[[function]]:

    squiffy.setArray=function(id, value){
        set("array"+id,value);
    }    

    squiffy.getArray=function(id){
        return(get("array"+id));
    }
    
    squiffy.story.go("initialize array");

[[initialize array]]:

    var loopCnt;
    
    //showing how a JS loop can work the array, inserting loop+5 values
    for (loopCnt=1; loopCnt<=3; loopCnt++){
        squiffy.setArray(loopCnt, loopCnt+5)
    }
    
Values loaded by loop

[[Fetch them back]]

[[Fetch them back]]:

    set("val1",squiffy.getArray(1));
    set("val2",squiffy.getArray(2));
    set("val3",squiffy.getArray(3));

Values should be 5+id, or 6,7,8...

{val1}<br>
{val2}<br>
{val3}<br>

If you have questions, let me know. Basically, the functions allow easy access off a poor-man's array index. You can load values in and pull them out fairly easily. And, if you don't want to bother (for single fetches, say, you can always just pull them out directly using the squiffy name (i.e. {array1})).

I use this for the various "Pathfinder" minigames to allow easier access to 2D and 3D maps. You might find a use for it. Enjoy!


Log in to post a reply.

Support

Forums