Just starting out? Need help? Post your questions and find answers here.
Andy
Posts: 46 Joined: Sat Feb 15, 2020 5:19 pm
Location: Larnaca, Cyprus
Contact:
Post
by Andy » Tue Mar 14, 2023 6:58 am
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.
Peter
Posts: 1046 Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:
Post
by Peter » Tue Mar 14, 2023 7:27 am
Static variables have a different name in JavaScript:
prefix: "so_" (I assume this stands for
s tatic
o bject).
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
Andy
Posts: 46 Joined: Sat Feb 15, 2020 5:19 pm
Location: Larnaca, Cyprus
Contact:
Post
by Andy » Tue Mar 14, 2023 2:08 pm
Thanks Peter. Is this stuff documented anywhere?
Peter
Posts: 1046 Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:
Post
by Peter » Tue Mar 14, 2023 2:57 pm
Is this stuff documented anywhere?
The naming rules are documented here:
Inline Javascript .
However, it seems to me that the static variables are missing.
Andy
Posts: 46 Joined: Sat Feb 15, 2020 5:19 pm
Location: Larnaca, Cyprus
Contact:
Post
by Andy » Wed Mar 15, 2023 8:28 pm
Looks like arrays are also missing
Fred
Site Admin
Posts: 1477 Joined: Mon Feb 24, 2014 10:51 am
Post
by Fred » Sat Mar 18, 2023 9:33 am
You can also put a calldebugger and open the webbrowser debugger to inspect the code and see how it's named.