Jump to content

[SOLVED] Set parameters for callback function at XML


photo

Recommended Posts

Class Widget has function to set callback:

WIDGET::setCallback (int callback, variable function, variable data_0,variable data_1, variable data_2, variable data_3)

This function can have up to 4 function parameters (data_0, data_1, data_2, data_3).

 

We can also set callback function name at ui-file

Source code (XML)
<callback type="clicked">Window::close_window</callback>

Can we set parameters for callback function at XML ?

Link to comment

Hi Dmitry,

 

Yes, you can easily set your custom parameters. For example:

<callback type="clicked" string="Hello">Window::close_window</callback>

void close_window(string FromXml) {

   log.message(FromXml);

}

All available parameters you can find here: https://developer.unigine.com/en/docs/1.0/code/gui/ui_widgets

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi Dmitry,

 

Yes, you can easily set your custom parameters. For example:

<callback type="clicked" string="Hello">Window::close_window</callback>

void close_window(string FromXml) {

   log.message(FromXml);

}

All available parameters you can find here: https://developer.unigine.com/en/docs/1.0/code/gui/ui_widgets

 

Thanks!

 

For string it works.

 

I would like to pass int parameter through XML.

I tried to use variable parameter, but didn't get success.

 

What should I do ?

Link to comment

Ok, thank you, it works.

 

How to use variable parameter, I didn't understand from Docs. There isn't clear for me too.

Where is declared this variable: in xml or in UnigineScript ? How to use it ?

Link to comment

You can pass variable by it's name, like this:

//cpp
int variable = 100500;

void callback(int var) {
 log.message("var: %d",var);
}
//ui
<checkbox align="expand">
   <callback type="clicked" variable="variable">callback</callback>
   <text>CheckBox</text>
</checkbox>

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...