Page 1 of 1
How define global array in JavaScript inline?
Posted: Wed Sep 25, 2024 11:38 am
by Caronte3D
I have a timer procedure where I need to use (and keep alive) an array, but I don't know how to define it globally with inline
If I do: let positions = []; inside the procedure, no error, but the array is empty each time te execution enters the Procedure, if I try to define it outside Procedure, an error tell me: Uncaught ReferenceError: positions is not defined
I tried to put the declaration inside an if to only do in one time, but SpiderBasic think it's not initialized
Re: How define global array in JavaScript inline?
Posted: Wed Sep 25, 2024 11:53 am
by Peter
Can you create a small example code that illustrates your problem?
Re: How define global array in JavaScript inline?
Posted: Wed Sep 25, 2024 12:09 pm
by Caronte3D
Code: Select all
Procedure Timer()
Define arraySize
!let positions = [];
!const currentValue = { one: 10.00, two: 20.00 };
!positions.push(currentValue);
!v_arraysize=positions.length;
Debug arraySize
EndProcedure
AddTimer(0, 1000)
BindEvent(#PB_Event_Timer, @Timer())
Re: How define global array in JavaScript inline?
Posted: Wed Sep 25, 2024 12:10 pm
by Caronte3D
I need !let positions = []; to be global, to not erase it each time it enters in Time procedure
Re: How define global array in JavaScript inline?
Posted: Wed Sep 25, 2024 12:32 pm
by Peter
Code: Select all
! positions = [];
Procedure Timer()
Define arraySize
!const currentValue = { one: 10.00, two: 20.00 };
!positions.push(currentValue);
!v_arraysize=positions.length;
Debug arraySize
EndProcedure
AddTimer(0, 1000)
BindEvent(#PB_Event_Timer, @Timer())
Re: How define global array in JavaScript inline?
Posted: Wed Sep 25, 2024 12:42 pm
by Caronte3D

I was trying with LET and VAR but I didn't know it was possible without anything (my JavaScript is near zero)
Thanks Peter

Re: How define global array in JavaScript inline?
Posted: Wed Sep 25, 2024 12:57 pm
by Peter
Caronte3D wrote: Wed Sep 25, 2024 12:42 pmI was trying with LET and VAR
I tried that first too.
JavaScript is a very flexible, but also dangerous language.
