Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1
My Carrier: Movistar
Accepted Solution

problem with if statements

hi, im having trouble to change the translation X to a label with an if statement, the app closes when reach the change of the text in my if, heres my relevant code

 

Label {
                visible: true
                id:battery
                text: ""
                translationY: 45
                translationX: -33
                textStyle.fontWeight: FontWeight.W400
                textStyle.fontSize: FontSize.PointValue
                textStyle.fontSizeValue:7
                horizontalAlignment: HorizontalAlignment.Right
                textStyle.textAlign: TextAlign.Left
                
                onTextChanged: {
                    if (_battery.level = 100){
                       translationXChanged(-27)
                    }
                } 

 and the _battery object

BatteryInfo {
            id: batteryinfo
            onLevelChanged: {
                battery.text = level + "%"
            }
        }

 any suggestions?

 

Highlighted
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: problem with if statements

[ Edited ]

Hmm, like some others on this forum you seem to be confused in the difference between assignment and comparison.

 

A single = means assign the value on the right to the left side object/variable.

A double == means compare the object on the right with the object on the left.

 

Your if statement will return true as you are effectively asking the if statement if you can assign a value of 100 to a variable.  However the battery level may be read only hence the crash.

 

@greenmr I can see you thinking should I put a more technically accurate explanation and also mention === but please don't let's keep it simple. Smiley Happy

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,177
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: problem with if statements

@BBSJdev

 

Nope... I'm good.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 1,177
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: problem with if statements

@BBSJdev... I think you just did mention ===

 



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1
My Carrier: Movistar

Re: problem with if statements

Thanks Smiley Happy