Spin "GOTO" Function??
You don't have to be too experienced to awnswer this one: Is there a Spin function like the BASIC function GOTO?·It might be even more handy if ther where a GOSUB-like instruction. This is my code:
PUB GetState(Modi,areg)
·····················
· serbyte2 := ReadByte(28,EEPROM,areg)
· serout_str(2,@serbyte2,2400,1,8)
· serin2 := serin_char(1,2400,1,8)
· if serin2==1
··· Modi := @on
· elseif serin2==2
··· Modi := @off
· else
··· Modi := @xxx·
After each Modi := etc. instruction I want it to return to·the next Mod on a list of them to scan.·If i use a return function, it returns to the top of the PUB routine that they are in and simply redoes it. Please Help!
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank you for reading!·
···
PUB GetState(Modi,areg)
·····················
· serbyte2 := ReadByte(28,EEPROM,areg)
· serout_str(2,@serbyte2,2400,1,8)
· serin2 := serin_char(1,2400,1,8)
· if serin2==1
··· Modi := @on
· elseif serin2==2
··· Modi := @off
· else
··· Modi := @xxx·
After each Modi := etc. instruction I want it to return to·the next Mod on a list of them to scan.·If i use a return function, it returns to the top of the PUB routine that they are in and simply redoes it. Please Help!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank you for reading!·
···
Comments
-Phil
GetState(Mod1,$8000)
GetState(Mod2,$8010)
GetState(Mod3,$8020)
Etc.
I want it to execute each command in order and I have VERY limited memory. Does anyone know how to do this??
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank you for reading!·
···
Do you mean that this works, but you don't have enough memory to have each call to GetState for every Modx?
CASE Serin2
1:
Modi := @on
2:
Modi := @off
OTHER:
Modi := @xxx
I think it returns to the last call point and processes the list. OR, if you have a true condition at the top, it will comeback and address the next true condition.
If that does not work you could wrap in in a Repeat.
Repeat until serin2 > 0 & serin2 < 3
.....
Or, maybe I'm confused as to why a GoTo would be necessary. A larger view of code might go a long way.
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
Edit: I agree strongly with Ned (below). Working your way through chapter 3 of the manual will do wonders.
Post Edited (sylvie369) : 3/16/2009 2:28:50 PM GMT
you can think of a Method as being just like a Subroutine, but you call it by name instead of a line number.
In structured languages, like Spin, what you end up doing is writing a bunch of small programs (subroutines, functions, methods, classes - they're just little programs), then you write a Main program, often just a loop, that calls each of the smaller programs when needed. If you've written anything big in Basic, you already know this concept, and I'm guessing you're pretty good with a BS2, yes?
Running through the tutorials in CH. 3 of the Propeller manual is worth every minute spent.
The Case statement, as CannibalRobotics pointed out, is your best bet any time you have stacked if's (p. 171 of the Prop manual)
Hanging on to GoTo and GoSub is like asking everybody to speak Latin. They are a hold over from a time long passed, and the more time you spend learning structured language concepts, the better prepared you'll be to work with a wide range of newer technologies. Work your way through Ch. 3 of the Prop Manual, and you'll be answering questions here, rather than asking them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"They may have computers, and other weapons of mass destruction." - Janet Reno
That's fun, very fun...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
In your case, you'd probably be using a simple REPEAT and a CASE statement.
One thing I noticed ... You use the STR call for SEROUT. This expects a zero-terminated string. It's not clear from your code whether your SERBYTE2 variable includes this. I don't know what serial I/O routines you're using, but there's probably one that takes a single character rather than the address of a character and that's the one you should use in this case (and not use the @).
Your assignments to Modi won't work either. Spin, like C, passes values to subroutines. If you want to be able to store into something, you need to pass the address, then use that. In your case, it might be easier to use the RETURN statement and that will both exit from GetState and provide a value to the caller. Since you're talking about using GOTOs, you may be wanting to return the label of a state routine. You can't do that in Spin the way you want. Rather than just present some examples that you might not want, how about explaining what you're trying to do and giving some of your own examples conceptually?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank you for reading!·
···
If you have a lot of states, it may be easier to split the CASE statement into several smaller CASE statements covering different ranges like:
Post Edited (Mike Green) : 3/16/2009 3:38:10 PM GMT
http://www.parallax.com/tabid/442/Default.aspx
This, again, is what makes Parallax so valuable to those of us just learning about these things: significant effort to document and educate, and then simply giving away that documentation.
Use this one:
http://www.rayslogic.com/propeller/Propeller%20Manual%20v1.01bmarked.pdf
I've added bookmarks that make it a whole lot easier to use!
(Parallax is cool to give these away as free downloads.)
@Ray, could we talk you into bookmarking this one as well?
With my background in old computers and various dialects of BASIC, I'm surprised
I don't miss GOTO and GOSUB more. I guess if I can adapt, anyone can. [noparse]:)[/noparse]
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Check out: Protoboard Introduction , Propeller Cookbook 1.4 & Software Index
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
Good Idea Rayman.
However, the very best is the paper manual. You won't be sorry.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank you for reading!·
···
I really feel sorry for people trying to get by without the bookmarked version... I still remember how it was driving me crazy trying to find things...