Results 1 to 4 of 4
  1.    #1  
    Hey everyone,

    I've just started doing some webOS development, and I have a basic scene working, but I"m having trouble reading a value from a ListSelector. I'm developing a very simple dice roller where you can pick the kind of die to roll, tap the roll button, and have the value displayed in a div. I have the rolling and displaying code working, but I can't seem to read the ListSelector. Here are some code snippets:
    this.die = 10;

    this.controller.setupWidget("dieSelector",
    this.attributes = {
    label: "Shape",
    choices: [
    {label: "d4", value: 4},
    {label: "d6", value: 6},
    {label: "d8", value: 8},
    {label: "d10", value: 10},
    {label: "d12", value: 12},
    {label: "d20", value: 20},
    ]},
    this.model = {
    value: this.die,
    disabled: false
    }
    );

    MenuAssistant.prototype.rollDice = function(event){
    this.controller.get("rolls").update(Math.floor(Math.random() * this.die) + 1);
    }



    No matter what I select in dieSelector, this.die remains 10. I've also tried accessing the value of the ListSelector model directly, but if that's what I"m supposed to do I must have the syntax wrong.

    Thanks in advance.
  2. #2  
    you probably need to do a Mojo.Event.propertyChange to change this.die (sounds a little morbid)
    My site: Shanerooni, LLC
    Follow me on Twitter
    My apps: GuessWhat? | MazeHunter3D | Small Wonders | PhakePhoney | AutismAware | PicSketcher | Cubix | QuickSolve | QuickSpell | QuickTrace | QuickWhack | QuickSuite | Soccer Shots | Ballooning |
    Cubix
  3. moserjj's Avatar
    Posts
    468 Posts
    Global Posts
    470 Global Posts
    #3  
    agreed, what shanerooni said - you should be using a propertyChange event. your code as-is will never update "this.die". something like this would probably work (again, use propertyChange event though...)

    Code:
    this.dieModel = {
    value: this.die,
    disabled: false
    };
    
    this.controller.setupWidget("dieSelector",
    this.attributes = {
    label: "Shape",
    choices: [
    {label: "d4", value: 4},
    {label: "d6", value: 6},
    {label: "d8", value: 8},
    {label: "d10", value: 10},
    {label: "d12", value: 12},
    {label: "d20", value: 20},
    ]},
    this.dieModel
    );
    
    MenuAssistant.prototype.rollDice = function(event){
    this.controller.get("rolls").update(Math.floor(Math.random() * this.dieModel.value) + 1);
    };
  4.    #4  
    Hey guys,

    So I ended up figuring a couple things out. I realized I was overwriting my models, so I abstracted a few things out:

    //die selector
    this.dieSelectorAttr = {
    label: "Shape",
    choices: [
    {label: "d4", value: 4},
    {label: "d6", value: 6},
    {label: "d8", value: 8},
    {label: "d10", value: 10},
    {label: "d12", value: 12},
    {label: "d20", value: 20},
    ]
    };
    this.dieSelectorModel = {
    value: this.die,
    disabled: false
    };
    this.controller.setupWidget("dieSelector", this.dieSelectorAttr, this.dieSelectorModel);


    So now there's a "this.dieSelectorModel" that can be referenced.

    When I click the button, I do an update with the new model and then roll the appropriate die pulled from the model:

    MenuAssistant.prototype.rollDice = function(event){
    this.controller.modelChanged(this.dieSelectorModel, this);
    this.controller.get("rolls").update(Math.floor(Math.random() * this.dieSelectorModel.value) + 1);
    }

    Ideally I should probably move the model changed call into a listener, but this is working at current, if updating the model unnecessarily.

Tags for this Thread

Posting Permissions