Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology
Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered
You are not logged in.
Pages: 1
hello
I have a button in my app. If a certain global variable == 0, I want a callback to execute with one of code. Once the button callback has executed once, I want to set the global variable to 1, and if that is the case, the button will execute with another block of code.
here is the global variable:
var scene_is_loaded = 0;;
here is the button callback declaration...it's in nested in a function executed once at startup, but for some (very obvious I'm sure) reason, the callback always assumes that the variable scene_is_loaded = =0 even after I have set it to 1:
//create open button callback when player is initialized
if (scene_is_loaded==0) then
(
setEdToolBarButtonCbClick tbstr chkstop mkfun5 @opendialog [viewstr loadwidget 0];
set scene_is_loaded = 1;
_DSalphaBitmap bmp;
SO3BufferUpdate viewstr.V3D_buffer;
0;
)
else
(
setEdToolBarButtonCbClick tbstr chkstop mkfun5 @opendialog [viewstr loadwidget 1];
0;
);
here is the button callback that sets the global variable to 1
fun opendialog(tbstr, check, btn, mask, extra_tuple)=
let extra_tuple -> [viewstructure widget sceneisloaded] in
(
if (sceneisloaded ==0) then
(
_DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win nil nil "OpenSpace 3D scene\0*.xos\0All\0*.*\0\0" @cbDlgOpenScene [viewstructure widget];
set scene_is_loaded = 1;
0;
) else
(
_DLGMessageBox _channel mainWindow.EDW_win "Error" "You have to clear that scene out first!" 0;
//code to clear scene and then once scene is cleared, execute _DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win nil nil "OpenSpace 3D scene\0*.xos\0All\0*.*\0\0" @cbDlgOpenScene [viewstructure widget];
0;
)
);
0;;
thx for your help....you can see my next question above, which is how to clear a scene out of the player. I looked at the editor, but the analogous function (new scene) is much more complicated.
perhaps I should be putting the call to the callback:
setEdToolBarButtonCbClick tbstr chkstop mkfun5 @opendialog [viewstr loadwidget 1];
somewhere else?
or can a button callback only be declared once?
thx for your help
-h
Offline
At the start :
var scene_is_loaded = 0;;
so, when you define the cb, this block is ran :
if (scene_is_loaded==0) then
(
setEdToolBarButtonCbClick tbstr chkstop mkfun5 @opendialog [viewstr loadwidget 0];
set scene_is_loaded = 1;
_DSalphaBitmap bmp;
SO3BufferUpdate viewstr.V3D_buffer;
0;
)
Precisely :
setEdToolBarButtonCbClick tbstr chkstop mkfun5 @opendialog [viewstr loadwidget 0];
The last item of your tuple is 0. So, in the callback, the value will be also 0.
Check directlly scene_is_loaded in your callback. Something like that :
fun opendialog(tbstr, check, btn, mask, extra_tuple)=
let extra_tuple -> [viewstructure widget] in
if (scene_is_loaded ==0) then
(
_DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win nil nil "OpenSpace 3D scene\0*.xos\0All\0*.*\0\0" @cbDlgOpenScene [viewstructure widget];
set scene_is_loaded = 1;
)
else
(
_DLGMessageBox _channel mainWindow.EDW_win "Error" "You have to clear that scene out first!" 0;
//code to clear scene and then once scene is cleared, execute _DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win nil nil "OpenSpace 3D scene\0*.xos\0All\0*.*\0\0" @cbDlgOpenScene [viewstructure widget];
set scene_is_loaded = 0; // i don't know, perhaps this line is useless
);;
//create open button callback when player is initialized
if (scene_is_loaded==0) then
(
setEdToolBarButtonCbClick tbstr chkstop mkfun5 @opendialog [viewstr loadwidget];
set scene_is_loaded = 1;
_DSalphaBitmap bmp;
SO3BufferUpdate viewstr.V3D_buffer;
0;
)
else
(
setEdToolBarButtonCbClick tbstr chkstop mkfun5 @opendialog [viewstr loadwidget];
0;
);
Offline
thx iri that works.
so button callbacks are only declared once, you can't change them. i'll (try) to remember that
never mind the question about clearing the scene i see it's already declared in the player pkg.
Offline
Yes, you can !
example :
fun myButtonCallback (objButton, param)=
_fooS param;
_CBbutton objButton @myButtonCallback "Alice";
0;;
...
_CBbutton button @myButtonCallback "Bob";
...
another example :
fun myButtonCallback (objButton, param)=
_fooS "clicked !";
_CBbutton objButton nil 0; // no cb set
0;;
...
_CBbutton button @myButtonCallback 0;
...
In your initial code, you could redefine the callback with 1 in the last item of the tuple when the scene is (re)loaded.
Offline
this is what i did....if there's a loaded scene or if the user has clicked on the open button and hits cancels, the scne is cleared:
fun opendialog(tbstr, check, btn, mask, extra_tuple)=
let extra_tuple -> [viewstructure widget viewstr sessionstr] in
(
if (scene_is_loaded ==0) then
(
_DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win nil nil "OpenSpace 3D scene\0*.xos\0All\0*.*\0\0" @cbDlgOpenScene [viewstructure widget];
set scene_is_loaded = 1;
0;
) else
(
initScene viewstr sessionstr;
_DLGMessageBox _channel mainWindow.EDW_win "Scene deleted!" "Scene deleted!" 0;
_DLGrflopen _DLGOpenFile _channel mainWindow.EDW_win nil nil "OpenSpace 3D scene\0*.xos\0All\0*.*\0\0" @cbDlgOpenScene [viewstructure widget];
0;
);
);
0;;
Offline
Pages: 1