Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC GOSUB command: local or global variables — Parallax Forums

PBASIC GOSUB command: local or global variables

ArchiverArchiver Posts: 46,084
edited 2003-05-08 17:11 in General Discussion
There is no scope at all! heh

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-05-07 21:42
    i am new to PBASIC and BasicStamps. I am using BS2p.
    How to pass variables to/from subroutines in PBASIC?
    Are there any distinction between global and local variables in
    PBASIC?
    Thanks
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-07 23:59
    Every variable is a global variable in PBASIC.

    -- Jon Williams
    -- Parallax

    In a message dated 5/7/2003 3:45:27 PM Central Standard Time,
    mohammedrasiq@y... writes:

    > i am new to PBASIC and BasicStamps. I am using BS2p.
    > How to pass variables to/from subroutines in PBASIC?
    > Are there any distinction between global and local variables in
    > PBASIC?
    > Thanks



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-08 14:58
    All variables are GLOBAL. In the BS2, they are
    actually registers on the chip.

    So, typically you'll have one or more interface variables
    for your subroutines. You'll set the variable, call
    the subroutine (which can change the variable) and
    then examine or use the variable's returned value.

    You can conserve variable space by defining a few
    'Temp1 VAR BYTE', 'Temp2 VAR BYTE' vars, and then
    ONLY using them as temporary variables inside
    subroutines (when your subs need a temp var).

    I've sometimes assigned 2 leading characters to my
    variables, to provide a pseudo 'namespace'. With
    the BS2 this is of limited value, since you want
    to reuse the limited register space.


    --- In basicstamps@yahoogroups.com, "mohammedrasiq"
    <mohammedrasiq@y...> wrote:
    > i am new to PBASIC and BasicStamps. I am using BS2p.
    > How to pass variables to/from subroutines in PBASIC?
    > Are there any distinction between global and local variables in
    > PBASIC?
    > Thanks
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-08 17:11
    Thanks Allan for your explanation. That was helpful!!

    --- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
    wrote:
    > All variables are GLOBAL. In the BS2, they are
    > actually registers on the chip.
    >
    > So, typically you'll have one or more interface variables
    > for your subroutines. You'll set the variable, call
    > the subroutine (which can change the variable) and
    > then examine or use the variable's returned value.
    >
    > You can conserve variable space by defining a few
    > 'Temp1 VAR BYTE', 'Temp2 VAR BYTE' vars, and then
    > ONLY using them as temporary variables inside
    > subroutines (when your subs need a temp var).
    >
    > I've sometimes assigned 2 leading characters to my
    > variables, to provide a pseudo 'namespace'. With
    > the BS2 this is of limited value, since you want
    > to reuse the limited register space.
    >
    >
    > --- In basicstamps@yahoogroups.com, "mohammedrasiq"
    > <mohammedrasiq@y...> wrote:
    > > i am new to PBASIC and BasicStamps. I am using BS2p.
    > > How to pass variables to/from subroutines in PBASIC?
    > > Are there any distinction between global and local variables in
    > > PBASIC?
    > > Thanks
Sign In or Register to comment.