How to use " If " in Code Editor the correct way

img

I used the code from generated code and used it in code editor, but it doesn’t work when " if " line in it.
Is the code wrong or it has to be done differently in code editor?

if () {
}

if(){
}else{
}

Thanks a lot, I tried it but no result, I’m having a little confusion. :grimacing:
Please, can you show me an example using my codes from the picture?

@Michael
Это проблема интерпретатора, возможно ошибка разработчика, а возможно это такая фишка.
Если не исправят, то обязательно опишу эту проблему в следующей статье.
Тут есть несколько моментов.

This is an interpreter problem, perhaps a developer error, or perhaps this is a feature.
If they don’t fix it, I will definitely describe this problem in the next article.
There are several points here.

  1. условие IF() всегда возвращает булев результат - да, нет.
    Когда Вы пишете такое условие, то в таких вариантах как visibe, можно не заморачиваться с проверкой. Так как само условие visible может быть либо да, либо нет, то ответ вы получите булевой в любом случае.

The IF() condition always returns a Boolean result - yes, no.
When you write such a condition, then in options such as visibe, you don’t have to bother with checking. Since the visible condition itself can be either yes or no, you will get a Boolean answer in any case.

import QtQuick 2.6

Item{
Connections {
    target: document.childByName("Button").scriptAdaptor
    onEventItemClicked: {
        if (document.childByName("TextField").visible) {
            document.childByName("TextField").content.scriptAdaptor.actionSetText("")
        }
    }
}
}
  1. Это тоже интересно, если Вы используете булево значение в коде в блоке проверки условия, то true не нужно вкладывать в скобки, а если Вы пытаетесь назначить такое значение, то применяются скобки “true”

This is also interesting, if you use a Boolean value in the code in a condition checking block, then true does not need to be enclosed in brackets, and if you are trying to assign such a value, then “true” brackets are used

import QtQuick 2.6

Item{
Connections {
    target: document.childByName("Button").scriptAdaptor
    onEventItemClicked: {
        if (document.childByName("TextField").visible == true) {
            document.childByName("TextField").content.scriptAdaptor.actionSetText("")
        }
    }
}
}

Так же обратите внимание, что если в условие выполняется только одно действие, то можно писать не применяя блок {}
Но если в вашем условии более одной команды, то все их нужно вписать в блок {}

Also note that if only one action is performed in a condition, then you can write without using the {} block
But if there is more than one command in your condition, then all of them need to be entered into the {} block

Thank you so much, you are an angel :sparkling_heart:


Back to Flipabit >
Copyright © 2018. Flipabit Team. All rights reserved.