Codes problem. Qml and Javascript



  • hi everyone im having a problem here you see my game.qml has this property
    @ id:scene
    width:360;height:640

    property int score: 0
    property int highScore:0
    property bool ready: false
    property bool paused: true
    property int level:0
    property int answered: 0
    
    signal clicked();
    signal levelLoaded();@
    

    it has a property level which is equal to 0

    and on my js file... i have this code

    @var answer;
    var question;

    //script for query
    var r = scene.level
    if(r == 0){
    first= Math.floor(Math.random()*19+1);
    second= Math.floor(Math.random()*19+1);
    answer=first+second;
    question=first+"+"+second;

    }@

    i want to use the property of my game.qml as a basis for the conditions on the if-else statements

    but everytime i do this. it always return this error/bug "scene[null] is not an object";

    anyone knows this?


  • Moderators

    We lack some info here. How did you include the JS file? Is the JS a library? Is the code you provided inside a function?



  • I am guessing he has the javascript in a separate file and he isn't including it. OP, its probably easier to just stick that javascript code into the same QML file that scene is in.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.