Jump to content
IGNORED

Action! DEFINE string


Recommended Posts

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!?

 

Link to comment
Share on other sites

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 by zbyti
common way
  • Like 1
Link to comment
Share on other sites

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 :)

  • Like 1
  • Haha 1
Link to comment
Share on other sites

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")

 

Link to comment
Share on other sites

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.

 

  • Like 2
Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

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.

 

                                   
 

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...