Shop OBEX P1 Docs P2 Docs Learn Events
Beginner Help with code — Parallax Forums

Beginner Help with code

TonyATonyA Posts: 226
edited 2007-07-03 13:00 in Propeller 1
I'm just starting to look at SPIN and working through the Propeller manual tutorial and am trying to complile and download this bit of code:

OBJ
  game_pad :  "gamepad_drv_001.spin"   'instantiating the gamepad driver object

PUB main
  game_pad.start                  'referencing the gamepad driver's start method
  game_pad.read                   'referencing the gamepad driver's read method
  
if (game_pad.button(NES0_UP)      'referencing the gamepad driver's button method. 
  DIRA[noparse][[/noparse]7]~~                       'If nes "up" button is pressed then make pin (7) an output
 
                                  'run the toggle loop.
Repeat
    !OUTA[noparse][[/noparse]7]                      'repeat the toggle process
    waitcnt(3_000_000 + cnt)      'timer
         

When I try to compile I get a message "Expected Expression" and NES0_UP is highlighted.

Could anyone offer advice?

Thanks in advance.





Post Edited (TonyA) : 7/3/2007 12:42:37 AM GMT

Comments

  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-07-03 00:42
    Unmatched brackets?
  • TonyATonyA Posts: 226
    edited 2007-07-03 01:20
    Well, I thought that constants from the driver were also imported? (I'm a little confused)
    When I added the CON block (see below), and then added another bracket;·(NES0_UP)), she complied.
    CON
      NES0_UP     = %00000000_00001000 
     
    OBJ
      game_pad :  "gamepad_drv_001.spin"   'instantiate the gamepad driver object
    
    PUB main
      game_pad.start                  'driver's start method
      game_pad.read                   'driver's read method
      
    if (game_pad.button(NES0_UP))     'driver's button method. 
      DIRA[noparse][[/noparse]7]~~                       {If nes up button is pressed then pin (7) is an output.}
                                      { run the toggle loop below.}
      Repeat
        !OUTA[noparse][[/noparse]7]                       'repeat the toggle process.
        waitcnt(3_000_000 + cnt)       'state of pin 7 with each pass through the loop.
        
    

    Thanks.

    Post Edited (TonyA) : 7/3/2007 1:34:27 AM GMT
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-07-03 01:35
    You need to prefix the constant with the object name and a #.

    So it's:

    game_pad#NES0_UP
  • TonyATonyA Posts: 226
    edited 2007-07-03 01:49
    I tried your suggestion; game_pad#NES0_UP and couldn't get it to compile.

    I was going by this (in the comment of the gamepad_drv_001) where it says;

    test if a specific button is down with:
    ' object_name.button(button_id)
    ' returns TRUE or FALSE

    The button id is: NES0_UP

    I'm just learning about OOP and programming (Outside of PBasic and PicBasic)·in general, but was wondering why I had to add the constant to the code of my top object when I am importing the driver?

    Also, would this still compile if incorrect?
    if (game_pad.button(NES0_UP)) 'driver's button method.

    Thanks again.

    Post Edited (TonyA) : 7/3/2007 2:29:33 AM GMT
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-07-03 03:03
    TonyA said...
    I tried your suggestion; game_pad#NES0_UP and couldn't get it to compile.

    It does compile.

    OBJ
      game_pad :  "gamepad_drv_001.spin"   'instantiating the gamepad driver object
    
    PUB main
      game_pad.start                  'referencing the gamepad driver's start method
      game_pad.read                   'referencing the gamepad driver's read method
     
    if (game_pad.button(game_pad#NES0_UP))      'referencing the gamepad driver's button method.
      DIRA[noparse][[/noparse]7]~~                       'If nes "up" button is pressed then make pin (7) an output
     
                                      'run the toggle loop.
    Repeat
        !OUTA[noparse][[/noparse]7]                      'repeat the toggle process
        waitcnt(3_000_000 + cnt)      'timer
    
  • TonyATonyA Posts: 226
    edited 2007-07-03 13:00
    Ok, I see now. I wasn't writing it that way. Still learning.

    Thanks.
Sign In or Register to comment.