Shop OBEX P1 Docs P2 Docs Learn Events
Passing array to a method — Parallax Forums

Passing array to a method

jsestijsesti Posts: 5
edited 2009-06-29 22:38 in Propeller 1
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!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-06-29 22:38
    You can't pass the array itself. That just passes the value of the first element. You need to pass the address like

    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 ])
Sign In or Register to comment.