Shop OBEX P1 Docs P2 Docs Learn Events
why wont this work? — Parallax Forums

why wont this work?

PFloyd36069PFloyd36069 Posts: 135
edited 2008-07-30 04:01 in Propeller 1
hi guys,

i am trying to send some info to an object but i cant get it to work. im not too good at spin yet so it is most likely not even close. here is my code...

········· pub start | title, album
··········· title:=string("Time")
············album:=string("Dark Side Of The Moon")
··········· info.start(@title, @album)

i am trying to send the title and album info to the object. when i run the program all i get is a P for the title.

thanks,

bryan

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-30 03:22
    string() already returns an address (of the string), so you don't need the "@" in the call to info.start.
  • DavidMDavidM Posts: 630
    edited 2008-07-30 03:27
    HI PFloyd,

    the two variables "title" & "album" you are using are declared as LONG INTEGERS because you are declaring LOCAL variables in the method "Start", all local variables declared this way will be LONG Integers.

    If you want to hold a "string" in a variable you will need to declare an array of bytes in the VAR block

    eg

    VAR
    BYTE Title[noparse][[/noparse]25]
    BYTE Album[noparse][[/noparse]25]

    this declares the variables 'Title" & Album" as string of 25 bytes each, then you can store the strings in them.

    Also the @ symbol makes the variable a reference to the address of the variable and not the contents of the variable ( also known as a pointer)

    Regards


    Dave M
  • jazzedjazzed Posts: 11,803
    edited 2008-07-30 03:56
    It is not necessary to declare space for a pointer to a fixed string. titleptr := string("Welcome to the Machine")
    It is however necessary to declare space if you want a copy of the contents of the string for some other use:

    var byte title[noparse][[/noparse]30]
    
    dat fishbowl byte "Wish You Were Here",0
    dat machine byte "Welcome to the Machine",0
    
    pub main | titleptr
      titleptr := string("The Wall")
      bytemove(@title,titleptr,strsize(titleptr)+1) ' +1 to copy null terminator too
      titleptr := @fishbowl
      bytemove(@title,titleptr,strsize(titleptr)+1) 
      bytemove(@title, @machine, strsize(@machine)+1)
    

    Danged editor :<···Added necessary indents in "pub main" lines.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (jazzed) : 7/30/2008 4:15:07 AM GMT
  • PFloyd36069PFloyd36069 Posts: 135
    edited 2008-07-30 04:01
    LOL jazzed.... Thanks guys i think i got it all figured out.
Sign In or Register to comment.