Replying to:CyberYoshi64
You forgot the @ under:
"Or something like this."
Correct syntax: GOTO@MNLOOP
Yeah, but I'm not going to edit it.
Root / Submissions / [.]
LEVEL%=5 WHILE <Some Condition> VSYNC IF LEVEL%==1 THEN '... ENDIF IF LEVEL%==2 THEN '... ENDIF IF LEVEL%==3 THEN '... ENDIF WENDOr something like this:
LEVEL%=5 @MNLOOP VSYNC IF LEVEL%==1 THEN GOTO @LEVEL1 IF LEVEL%==2 THEN GOTO @LEVEL2 IF LEVEL%==3 THEN GOTO @LEVEL3 GOTO MNLOOP @LEVEL1 '... GOTO @MNLOOP @LEVEL2 '... GOTO @MNLOOP @LEVEL3 '... GOTO @MNLOOPThese two examples shares a common problem: It destroys code readability and makes it near impossible to debug if you end up adding like 30 segments of predefined code. So, what's the solution for this? The solution is using DATA.
DATA <data 1>, <data 2>... DATA "This is data",2,3.5,&HFF00FF00,&B0010,#UP 'Note: all the functions, including user functions, won't work on DATA. Since DATA only handles constant expressions
DATA 1,2,3,4,5 READ X ? XOUTPUT: 1
DATA 1,2,3,4,5 READ X READ Y ? YOUTPUT: 2 So, if you want to access to the 5th element of a DATA set, you need to run READ 4 times before. So, on much cases you will end up using a FOR loop.
DATA 1 READ X ? X DATA 2OUTPUT: 1
RESTORE @B DATA 1 READ X ? X @B DATA 2OUTPUT: 2 With this now we can start.
DATA "Author","Message",&HFFFFFF,5 ' White message with a duration of 5 secondsNow, we set an "ID" to the DATA segments we are going to use, by using a @Label:
@TEST DATA "Author","Message",&HFFFFFF,5With this setup, we can start making the DATA Parser.
DIM ARG$[5], DELAY%,GC,PREV_MILI% RESTORE @TEST WHILE 1 VSYNC GCLS 'DATA Parser for messages IF !DELAY% THEN 'I read the necessary arguments before showing anything. Yours can vary based on your needs. READ ARG$[0] READ ARG$[0] READ GC READ DELAY% ELSE GPUTCHR 10,120,ARG$[0] GCOLOR GC GPUTCHR 10,130,ARG$[1] ENDIF 'Clock in seconds IF PREV_MILI%+1000 < MILLISEC THEN DELAY%=DELAY%-1 PREV_MILI%=MILLISEC ENDIF WEND @TEST DATA "Author","Message",&HFFFFFF,5Aaaaannndddd... Well, that's all, for a very simple reason: When the DATA Parser is ready, most of your editions will go on the DATA statements and not on the core structure. With that you can sepparate the logic from the arguments, and have a more cleaner code that will not only look "good" (every code is a mess, but anyways), but it will save you time when you want to make quick edits to the levels or the stuff you're showing. What if you want to add or erase messages? Just add more DATA like this:
@TEST DATA "Me","This is a message using DATA statements (DUR: 5 secs)",&HFFFFFFFF,5 DATA "Me","Is amazing because i don't have to touch the core structure to add more and more (DUR: 5 secs)",&HFFFFFFFF,5 DATA "Someone else","Also, this message is plain red (DUR: 5 secs)",&HFFFF0000,5 DATA "Me","And this message last 3 seconds and is blue (DUR: 3 secs)",&HFF0000FF,3