![]() |
Forum Index : Microcontroller and PC projects : CMM2 - function$ for CALL somehow limited, bug?
Author | Message | ||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi, I used in program for programming challenge CALL command for very simple and effective key->routine selector and found some (for me) strange behaviour: This code is working key$= "abc" func$="nabc" DO fun$ = MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1) CALL fun$ LOOP END SUB n 'empty function, needed for no key press END SUB SUB a ?a END SUB SUB b ?b END SUB SUB c ?c END SUB But when I put it all into CALL DO CALL MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1) LOOP I will get Argument list error. But some primitive string handling are working properly. Is it a bug? Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Check the manual. I'm surprised the first version works - certainly not by design |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
I'm missing something, in what way does the manual entry suggest that this wouldn't work? Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
|
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Still not getting it Peter: n, a, b & c are USER defined subroutines. Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
I don't see here anything wrong fun$ = MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1) CALL fun$ When it will be fun$ = "MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1)" then it will be calling built-in function.CALL fun$ But interesting is, when I will change it to key$= "abc" Then it will work OK, so some calculations are allowed in CALL...func$="nabc" DO fun$ = MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1) CALL "f" + fun$ LOOP END SUB fn 'empty function, needed for no key press END SUB SUB fa ?a END SUB SUB fb ?b END SUB SUB fc ?c END SUB Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Yes but MID$ isn't so CALL MID$(func$, INSTR(keys$, LCASE$(INKEY$)) + 1, 1) can't work. Everything after the CALL command is interpreted as though it was normal inline code but you can't have two in-built command tokens in a row You are correct of course about CALL fun$ that is what it is designed for - me being stupid |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
EDIT: written before Peter's previous response. My guess is that the parser thinks one of the commas in MID$ or INSTR is a parameter separator in the CALL command. But I could be talking tripe, Tom Edited 2021-04-05 03:22 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Thanks Peter, clear with more than one token. In normal life (not one page challenge ![]() I still think it's pretty effective way to select routines depending on key, you have just one condition, all function names need to have exact same length. Maximum length of func$ can be solved with LONGSTRING if needed. Selector with 5 characters per function: key$= "abc" func$="emptyFUNCaFUNCbFUNCc" DO fun$ = MID$(func$, 5*INSTR(keys$, LCASE$(INKEY$)) + 1, 5) CALL fun$ LOOP SUB empty 'empty function, needed for no key press END SUB SUB FUNCa ?a END SUB SUB FUNCb ?b END SUB SUB FUNCc ?c END SUB Edited 2021-04-05 03:36 by jirsoft Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |