Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED][Moved] Destroying Objects Based on text and buttons
Forum Updated to NodeBB v4.3 + New Features

[SOLVED][Moved] Destroying Objects Based on text and buttons

Scheduled Pinned Locked Moved QML and Qt Quick
14 Posts 5 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lexan
    wrote on last edited by
    #1

    hi, were trying to destroy objects based on numbers displayed on text..
    whenever the user clicks on buttons numbers will be displayed on text.. these will be the basis for the destruction of objects.. but were kinda having a problem

    i have this javascript function to verify answer of the user

    @function verify(t){
    for(var i=0;i<maxIndex;i++){
    if(fireArray[i]!=null){
    if(fireArray[i].answer==displayText.toString()){
    fireArray[i].visible=false;
    fireArray[i]=null;
    index--;
    fireArray.sort();
    return true;
    }
    }
    }
    return false;
    }@

    this is my codes for displayText

    @ Text {
    id: displayText
    x: 82
    y: 75
    anchors {
    right: parent.right; verticalCenter: parent.verticalCenter; verticalCenterOffset: 76
    rightMargin: 19; bottom:sip.bottom
    }
    font.pixelSize: 31; text: "0"; anchors.bottomMargin: -77; horizontalAlignment: Text.AlignRight; elide: Text.ElideRight
    color: "#343434"; smooth: true; font.bold: true

             }@
    

    so how will i do it?

    i love panda

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chuck Gao
      wrote on last edited by
      #2

      Sorry, but i can't understand what you mean. Which one you want to destroyed explicitly ?

      Chuck

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thisisbhaskar
        wrote on last edited by
        #3

        what is this fireArray, is it array of buttons or something else?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lexan
          wrote on last edited by
          #4

          @chuck gao: Im trying to destroy falling objects.. this post is related to my previous post

          @Vijay Bhaska Reddy: its an array of falling objects..

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thisisbhaskar
            wrote on last edited by
            #5

            ok.. what is the problem you are facing.. does the falling objects become invisible when you set visible to false?? or your problem is something else.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              [quote author="lexan" date="1311225300"]@chuck gao: Im trying to destroy falling objects.. this post is related to my previous post
              [/quote]

              I'm not sure all who read this post knows about your prev post (I read through all forum posts, but remember only part of them), so, please when you start new post leave a link or describe problem more detailed.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lexan
                wrote on last edited by
                #7

                actually nothing happens. i was expecting that every time i input a correct answer the falling object would be invisible.. but to no avail

                @chuck gao: sorry Im kinda confused on what to do so i wasnt able to focus on what to say right now

                http://developer.qt.nokia.com/forums/viewthread/7531/

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thisisbhaskar
                  wrote on last edited by
                  #8

                  Can you give your code if its ok with you.. for me it looks like it should work. Zip your entire project directory and upload to some file uploading site and post the link here..

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lexan
                    wrote on last edited by
                    #9

                    hi vijay

                    this is the link of the application im trying to do.. all i want to do in my sort of typing maniac game is that every time user inputs his answer the falling objects will be destroyed

                    anyway this is my link

                    http://www.4shared.com/folder/mhLcfD8p/_online.html

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      xsacha
                      wrote on last edited by
                      #10

                      Ok, I just checked it out.

                      Now, here's the first important part (why your code isn't working):

                      @Button { y: -1; width: 48; height: 26; color: 'purple'; smooth: false; opacity: 1; operation: "Ok" }
                      MouseArea{
                      ....
                      }
                      @
                      The MouseArea needs to be inside the Button. And most importantly, it needs to take up the whole button (anchors.fill: parent).

                      Now, I've a simpler solution. It seems you created a 'clicked' signal for Button that you aren't using.
                      Time to use it.

                      Old code
                      @ Button { y: -1; width: 48; height: 26; color: 'purple'; smooth: false; opacity: 1; operation: "Ok" }
                      MouseArea{
                      anchors.fill: parent
                      onClicked:{
                      if(answerr!=""){
                      if(Logic.verify(text))
                      text=""
                      }
                      }
                      }
                      }@

                      Fixed code
                      @ Button { y: -1; width: 48; height: 26; color: 'purple'; smooth: false; opacity: 1; operation: "Ok"
                      onClicked:{
                      if(answerr!=""){
                      if(Logic.verify(text))
                      text=""
                      }
                      }
                      }
                      @
                      Although, I'd go further and suggest integrating your button changes in to Button.qml itself since all the buttons look the same ;).

                      Now, the second important part:
                      @if(answerr!=""){@
                      What's answerr? I can't find any similar variable in that QML file but I assume it is just display.text. The thing is, your verify function doesn't even use this value -- so it isn't required here.

                      Fixed code
                      @Button { y: -1; width: 48; height: 26; color: 'purple'; smooth: false; opacity: 1; operation: "Ok"
                      onClicked: Logic.verify();
                      }@

                      Now here's the third important part. You may be wondering why I removed some of the code like clearing the textbox -- well you can do this in the Javascript.

                      Old Code (with luzon code added in)
                      @function verify(){
                      for(var i=0;i<maxIndex;i++){
                      if(fireArray[i]!=null){
                      if(fireArray[i].answer==display.text){
                      fireArray[i].visible=false;
                      fireArray[i]=null;
                      index--;
                      fireArray.sort();
                      display.text="";
                      return true;
                      }
                      }
                      }
                      return false;
                      }@

                      This code is fine.

                      But we need to make sure that fireArray[i].answer exists.

                      In Fire.qml:
                      @AnimatedImage{
                      property string answer: Logic.answer
                      id:fire@
                      and remove:
                      @id: answer@
                      in the Text element.

                      Working fine now :)

                      P.S. Debugging: You can use console.log(variable) in QtCreator and it will print out the variables value for you. For example, console.log(fireArray[i].answer) will always be 'undefined' in your original code.

                      • Sacha
                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        lexan
                        wrote on last edited by
                        #11

                        the answer refers to the answer displayed on the falling object.. i have decided to put the answer on the falling object along with the question so that that will be the peg for my verification.. it resides on another qml file... i'll just have to change its opacity so as to hide it.. well that's my idea..

                        though.. still not work... i have tried what you have posted here..

                        i think i have to clean up my codes first..

                        1 Reply Last reply
                        0
                        • X Offline
                          X Offline
                          xsacha
                          wrote on last edited by
                          #12

                          Ok, I will do quick summary:

                          Luzon.qml
                          @ Row{
                          x: -1
                          y: -29
                          Button { y: -1; width: 48; height: 26; color: 'purple'; smooth: false; opacity: 1; operation: "Ok"
                          onClicked: Logic.verify(); // turned MouseArea code in to this
                          }

                                  }@
                          

                          Logic.js
                          @function verify(){ // remove 't' variable
                          for(var i=0;i<maxIndex;i++){
                          if(fireArray[i]){
                          if(fireArray[i].answer==display.text){
                          fireArray[i].visible=false; // this is redundant
                          fireArray[i]=null;
                          index--;
                          fireArray.sort();
                          display.text=""; // added this
                          return true;
                          }
                          }
                          }
                          return false;
                          }@

                          Fire.qml
                          @AnimatedImage{
                          property string answer: Logic.answer // added this
                          id:fire
                          ...

                          Text{
                          

                          // id: answer <-- removed this
                          x: 10
                          y: 10
                          color: "#ffffff"
                          text: qsTr(" "+Logic.answer)@

                          Any questions, just ask :)

                          • Sacha
                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            lexan
                            wrote on last edited by
                            #13

                            haha. thanks xsacha.. I have decided to clean up my codes first and rearrange some and then I included your modifications.. THANKS it finally worked.. the only thing is i have to change my design because I believe mine was poorly designed.. :D THANK YOU VERY MUCh.. one of my three problems in my game is now considered solved :D

                            *but before anything else.. i just wanna know exactly what are my mistakes? and what's the reason behind some exclusion of old codes and inclusion of new ones in mine?

                            1 Reply Last reply
                            0
                            • X Offline
                              X Offline
                              xsacha
                              wrote on last edited by
                              #14

                              Well the first mistake was that your MouseArea which calls 'Logic.verify()' was never being pressed
                              So your Javascript function, verify(), never got a chance to run at all.
                              The reason was because the MouseArea didn't have an area associated with it. It was outside the Button. To solve this, the MouseArea needed to be inside the button with "anchors.fill: parent". I chose the simpler solution of "onClicked", however, as I noticed you have a clicked signal.

                              The second mistake was fireArray[i].answer was not what you thought it was. It was a Text element. You can't compare that to a string like "8" :P.
                              So my solution was to remove the 'answer' id which was associated to the Text element and instead make 'answer' a string property associated with Logic.answer (that is, the value you use).

                              As for why I removed the 't' variable and the isVisible: they weren't used/redundant.

                              • Sacha
                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved