Definition and construction of algorithms

 

Here is the code used in this lesson:



//ALGORITHMS

Application {
OnInit {
broker.ui.push("Main")
//Executed at application startup

}

OnResume {
//Executed when application's state goes to foreground

}

OnEnterBackground {
//Executed just before application's state goes to background

}
}

Experience Main1 {
OnCreate {
//Executed when the experience is created through a push or present navigation statement for the first time

}

OnResume {
//Executed whenever the experience can be viewed, i.e. it reaches the top of the navigation stack

}

OnDestroy {
//Executed before its destruction, through a pop or dismiss navigation statement
}
}

RuleContext ruleContext {
Rule rule {
//Executed every time it is invoked through an event
}
}

Module module {
void function () {
//Executed every time it is invoked or through an event
}
}

///////////////////
Experience Main {
Integer op1 as TextField
Integer op2 as TextField

Decision rule1 action("ctx.calculate") label("Calculate")

Integer result as Label
}

RuleContext ctx {
Rule calculate {
Main m = broker.ui.getDataSource()

if (m.op1 != null && m.op2 != null) {
m.result = m.op1 * m.op2

broker.ui.showAlert("Success!", "The result is: " + m.result.toString())
} else {
broker.ui.showAlert("Error!", "Complete all fields.")
}
}
}

> Next