Getting mutiple results from multiple objects
Good morning,
I've been trying to figure out something for a few days now when using mutiple objects. Say in one object :
test.spin:
test2.spin
If I use 'return resultvar[0]' in test.spin I get the result, but how do I get it to return each result 0,1,2 ?
Thanks
I've been trying to figure out something for a few days now when using mutiple objects. Say in one object :
test.spin:
PUB thisone
resultvar[0] := 100 'Y result
resultvar[1] := 200 'U result
resultvar[2] := 235 'V result
return
and in another object I want to get those results for each resultvar and use themtest2.spin
PUB Start
PST.DEC(test.thisone)
return
If I use 'return resultvar[0]' in test.spin I get the result, but how do I get it to return each result 0,1,2 ?
Thanks
Comments
long[@resultvar][index]
You really should post all your code we can't see resultvar's declared type or if it is a VAR or DAT.
TEST.SPIN
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long resultvar[3] PUB Start resultvar[0] := 100 resultvar[1] := 200 resultvar[2] := 135 return resultvar[0]
TEST2.SPIN
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long something[3] OBJ PST: "Parallax Serial Terminal" tryit: "TEST" PUB Start | i PST.Start(115_200) Pause(2_000) PST.Dec (tryit.Start) 'this is where I and trying to get all 3 resultvar results return
test.spin
VAR long resultvar[3] PUB Start resultvar[0] := 100 resultvar[1] := 200 resultvar[2] := 135 return @resultvar PUB GetResultVar(idx) return resultvar[idx]
Test2.spin
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long something[3] OBJ PST: "Parallax Serial Terminal" tryit: "TEST" PUB Start | i, array PST.Start(115_200) Pause(500) array := tryit.Start 'this is where I and trying to get all 3 resultvar results pst.str(string("array[0] = ")) pst.dec(long[array][0]) pst.char(13) pst.str(string("array[1] = ")) pst.dec(long[array][1]) pst.char(13) pst.str(string("array[2] = ")) pst.dec(long[array][2]) pst.char(13) pst.str(string(13,"------------------------",13)) pst.char(13) pst.str(string("GetResultVar(0) = ")) pst.dec(tryit.GetResultVar(0)) pst.char(13) pst.str(string("GetResultVar(1) = ")) pst.dec(tryit.GetResultVar(1)) pst.char(13) pst.str(string("GetResultVar(2) = ")) pst.dec(tryit.GetResultVar(2)) pst.char(13) PRI Pause(Duration) waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt) return return
I spent the better part of the day yesterday going through the prop manual working with longs/words/bytes and honestly at times it got more confusing as I went along, there was a section that said something to the effect that global vars were only able to be used in the object it was written in and I took that the wrong way.... I also went through the forums and found some posts that were along the lines of what I was trying to do, but they were mostly about launching methods into other cogs(which I though about, but I don't want to add to my confusion!) Thank you again!