+Ripdubski Posted February 12, 2021 Share Posted February 12, 2021 How does one use DEFINE to set a string value? Such as: DEFINE SSREADY = "TEST" PROC Main() PrintF("SSREADY=[%S]%E", SSREADY) RETURN This will not compile correctly as TEST is SSREADY is replaced by TEST without quotes. Double quoting results in syntax error, but it is how you embed a double quote in a string. I've tried these as well which won't work either: DEFINE SSREADY=""TEST"" DEFINE SSREADY='"TEST"' Is this just not possible with Action!? Quote Link to comment Share on other sites More sharing options...
zbyti Posted February 13, 2021 Share Posted February 13, 2021 (edited) DEFINE not work this way. DEFINE simply replacing during compilation your DEFINE shortcut with his "value". Edited February 13, 2021 by zbyti typo Quote Link to comment Share on other sites More sharing options...
Alfred Posted February 13, 2021 Share Posted February 13, 2021 What zbyti says. The value of DEFINE is a string constant and cannot be an actual string. You would need to define a string variable separately and then use DEFINE to substitute it. 1 Quote Link to comment Share on other sites More sharing options...
zbyti Posted February 13, 2021 Share Posted February 13, 2021 (edited) Fun way to use DEFINE in Action! DEFINE PLUS = "+" DEFINE I = "+" DEFINE TRZY = "3" DEFINE DZIESCI = "* 10" DEFINE PISZ = "PRINTF(""%U%E"", " DEFINE NA = ")" DEFINE EKRAN = "" PROC MAIN() PISZ TRZY DZIESCI I TRZY PLUS TRZY NA EKRAN PISZ TRZY PLUS TRZY I TRZY NA EKRAN RETURN Most common way: DEFINE RIGHT = "1" DEFINE LEFT = "-1" DEFINE UP = "-40" DEFINE DOWN = "40" DEFINE XY="+40*" IF STICK0=7 AND PLAYERPOS(RIGHT)=NOTHING THEN PLAYERPOS ==+ RIGHT FI IF STICK0=11 AND PLAYERPOS(LEFT)=NOTHING THEN PLAYERPOS ==+ LEFT FI IF STICK0=13 AND PLAYERPOS(DOWN)=NOTHING THEN PLAYERPOS ==+ DOWN FI IF STICK0=14 AND PLAYERPOS(UP)=NOTHING THEN PLAYERPOS ==+ UP FI Edited February 13, 2021 by zbyti common way 1 Quote Link to comment Share on other sites More sharing options...
thank you Posted February 13, 2021 Share Posted February 13, 2021 43 minutes ago, zbyti said: Fun way to use DEFINE in Action! DEFINE PLUS = "+" DEFINE I = "+" DEFINE TRZY = "3" DEFINE DZIESCI = "* 10" DEFINE PISZ = "PRINTF(""%U%E"", " DEFINE NA = ")" DEFINE EKRAN = "" PROC MAIN() PISZ TRZY DZIESCI I TRZY PLUS TRZY NA EKRAN PISZ TRZY PLUS TRZY I TRZY NA EKRAN RETURN I am pretty sure, this way madness lies 1 1 Quote Link to comment Share on other sites More sharing options...
+Ripdubski Posted February 13, 2021 Author Share Posted February 13, 2021 I understand what its intent is and what it does. I dont understand how or if it works with string values. I have no issues with numberic values. I think maybe I misconveyed what I'm trying to do. From the complex example in the reply, the double quoted double quotes dont achieve the desired result. From my code, I want to achieve: DEFINE SSREADY = "TEST" PROC Main() PrintF("SSREADY=[%S]%E", SSREADY) RETURN into Net result: PrintF("SSREADY=[%S]%E", "TEST") Quote Link to comment Share on other sites More sharing options...
+Ripdubski Posted February 13, 2021 Author Share Posted February 13, 2021 I found the solution. Since DEFINE needs double quotes surrounding the value, the double quotes I want around the string need the second set of double quotes, which means there are 3 double quotes around the text. To add to the confusion, there must be a space between the 1st and 2nd/3rd (pair), same on the end. This works: DEFINE SSREADY = " ""TEST"" " PROC Main() PrintF("SSREADY=[%S]%E", SSREADY) RETURN translates to result: PrintF("SSREADY=[%S]%E", "TEST" ) and produces output: SSREADY=[TEST] If you cram all the quotes together it doesn't work right. 2 Quote Link to comment Share on other sites More sharing options...
zbyti Posted February 13, 2021 Share Posted February 13, 2021 37 minutes ago, Ripdubski said: I found the solution. Since DEFINE needs double quotes surrounding the value, the double quotes I want around the string need the second set of double quotes, which means there are 3 double quotes around the text. To add to the confusion, there must be a space between the 1st and 2nd/3rd (pair), same on the end. This works: DEFINE SSREADY = " ""TEST"" " PROC Main() PrintF("SSREADY=[%S]%E", SSREADY) RETURN translates to result: PrintF("SSREADY=[%S]%E", "TEST" ) and produces output: SSREADY=[TEST] If you cram all the quotes together it doesn't work right. I consider it a bug not future. But hey, it's Action! if it works then works Quote Link to comment Share on other sites More sharing options...
Alfred Posted February 13, 2021 Share Posted February 13, 2021 Yeah, it's not clear why that works. Here are the relevant parts from the cartridge: ; <def dcl> ..:= DEFINE <def list> ; <def list> ..:= <def list> , <def> | <def> ; <def> ..:= <id> = <str const> dcl200 jsr mkent ; DEFINE - create name ldy #0 lda #defid ; store data type sta (props),y jsr getnxt cmp #eqlid ; always have to have bne dclerr ; an assign for define lda nxttkn cmp #quote bne dclerr ldy #0 lda (symtab),y clc adc #2 ; real size + EOL jsr stincr ; save string from overwrite jsr getnxt ; string itself jsr getnxt ; dummy string jsr getnxt cmp #comma ; look for more dcl210 bne dcl140 ; whoops, go back some beq dcl200 dclerr ldy #dcler jmp splerr So the cart is trying to pull three tokens following the "=", which I don't quite understand. The first getnxt will be to pull the first quote forward to enable the string getter to build the string token: ; LexStr() ; -------- lexstr lda token cmp #quote beq pback ; zap local st lda #0 sta arg9 lxs010 jsr nxtchr inc arg9 beq lxs030 ; string too long cmp #'" beq lxs040 lxs020 ldy arg9 sta (symtab),y lda chan bpl lxs010 ; if not EOF lxs030 ldy #strer jmp splerr lxs040 jsr nxtchr cmp #'" beq lxs020 ; " in string ; end of string ldy arg9 lda #eol sta (symtab),y dey tya ldy #0 sta (symtab),y ; save size lda symtab ldx symtab+1 ldy choff ; PUT THE 2 QUOTES BACK dey jmp ldig2 You can see it is watching for embedded quotes, which appear to be back to back. I guess the space breaks the two quote sequence, allowing the final quote to close the string. I think the three quotes together would have given you an embedded pair of quotes in the final string which probably would break the expander. Good find though. 1 Quote Link to comment Share on other sites More sharing options...
zbyti Posted February 13, 2021 Share Posted February 13, 2021 (edited) . Edited February 13, 2021 by zbyti not relevant Quote Link to comment Share on other sites More sharing options...
+slx Posted February 14, 2021 Share Posted February 14, 2021 Action!‘s one-pass compiler is so prescient it thinks triple quotes are a Python comment Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.