Passing array to a method
jsesti
Posts: 5
Hello,
· I think I am having trouble passing an array within a method to another method.· Here is an example of what I mean:
VAR
·· byte testing[noparse][[/noparse]4]
·· long stack[noparse][[/noparse]200]
PUB Method_A
· testing[noparse][[/noparse]0]:=1
· testing[noparse][[/noparse]1]:=2
· testing[noparse][[/noparse]2]:=3
· testing[noparse][[/noparse]3]:=4
· cognew(Method_B(testing), @Stack)
PUB Method_B (testingX)
· ToggleLED(testingX[noparse][[/noparse]0]) ' should toggle LED 1 time
· ToggleLED(testingX[noparse][[/noparse]1]) ' should toggle LED·2 times
· ToggleLED(testingX[noparse][[/noparse]2]) ' should toggle LED 3 times
· ToggleLED(testingX[noparse][[/noparse]3]) ' should toggle LED 4 times
Only the code for testingX[noparse][[/noparse]0] toggle the LED properly.· The rest toggle the LED indefinitely.
My question is:· Am I passing the array value in the correct way?· I have a feeling I am only passing the first element in the 'testing' array.· I think my syntax is wrong.
Your help is appreciated!
· I think I am having trouble passing an array within a method to another method.· Here is an example of what I mean:
VAR
·· byte testing[noparse][[/noparse]4]
·· long stack[noparse][[/noparse]200]
PUB Method_A
· testing[noparse][[/noparse]0]:=1
· testing[noparse][[/noparse]1]:=2
· testing[noparse][[/noparse]2]:=3
· testing[noparse][[/noparse]3]:=4
· cognew(Method_B(testing), @Stack)
PUB Method_B (testingX)
· ToggleLED(testingX[noparse][[/noparse]0]) ' should toggle LED 1 time
· ToggleLED(testingX[noparse][[/noparse]1]) ' should toggle LED·2 times
· ToggleLED(testingX[noparse][[/noparse]2]) ' should toggle LED 3 times
· ToggleLED(testingX[noparse][[/noparse]3]) ' should toggle LED 4 times
Only the code for testingX[noparse][[/noparse]0] toggle the LED properly.· The rest toggle the LED indefinitely.
My question is:· Am I passing the array value in the correct way?· I have a feeling I am only passing the first element in the 'testing' array.· I think my syntax is wrong.
Your help is appreciated!
Comments
cognew(Method_B(@testing),@Stack)
In Method_b, you'd have things like
ToggleLED(long[noparse][[/noparse]testingX][noparse][[/noparse] 0 ])
ToggleLED(long[noparse][[/noparse]testingX][noparse][[/noparse] 1 ])