Page 1 of 1
Static keyword confusion
Posted: Tue Mar 14, 2023 6:58 am
by Andy
Code: Select all
Procedure ButtonHandler()
Static value
If value = 0
value = 20
EndIf
! console.log(v_value)
EndProcedure
If OpenWindow(0, 0, 0, 300, 440, "Test", #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 280, 30, "Click Me")
BindGadgetEvent(0, @ButtonHandler())
EndIf
When I use the Static keywork inside a procedure where inline Javascript needs to access the static variable, Javascript complains that the variable is not defined.
Re: Static keyword confusion
Posted: Tue Mar 14, 2023 7:27 am
by Peter
Static variables have a different name in JavaScript:
prefix: "so_" (I assume this stands for
static
object).
plus: procedure-name
plus: $-sign
plus: variable-name
In your case:
so_buttonhandler$v_value
Code: Select all
Procedure ButtonHandler()
Static value
If value = 0
value = 20
EndIf
! console.log(so_buttonhandler$v_value)
EndProcedure
Re: Static keyword confusion
Posted: Tue Mar 14, 2023 2:08 pm
by Andy
Thanks Peter. Is this stuff documented anywhere?
Re: Static keyword confusion
Posted: Tue Mar 14, 2023 2:57 pm
by Peter
Is this stuff documented anywhere?
The naming rules are documented here:
Inline Javascript.
However, it seems to me that the static variables are missing.
Re: Static keyword confusion
Posted: Wed Mar 15, 2023 8:28 pm
by Andy
Looks like arrays are also missing
Re: Static keyword confusion
Posted: Sat Mar 18, 2023 9:33 am
by Fred
You can also put a calldebugger and open the webbrowser debugger to inspect the code and see how it's named.