Author Topic: Functions ?  (Read 2155 times)

Offline Hotshot

  • Mc. Print
  • *
  • Posts: 22
    • View Profile
Functions ?
« on: 2012-Aug-15 »
Hello Everyone

I going to give GLBASIC Second chance and give a try :)

Code: (glbasic) [Select]
GLOBAL BACKGROUND=0

LOADSPRITE "picture.PNG", BACKGROUND

FUNCTION SHOW_BACKGROUND:

         DRAWSPRITE BACKGROUND, 100, 100


ENDFUNCTION

SHOW_BACKGROUND()

SHOWSCREEN
MOUSEWAIT
END

What wrong with the code as it saying

"MYFIRSTPROGRAM.gbas"(31) error : command not inside function or sub


Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: Functions ?
« Reply #1 on: 2012-Aug-15 »
Hi Hotshot,

try placing the function after the function call:

Code: (glbasic) [Select]
GLOBAL BACKGROUND=0

SETSCREEN 640,480,1

LOADSPRITE "picture.PNG", BACKGROUND

SHOW_BACKGROUND()

SHOWSCREEN

MOUSEWAIT

END

// This is your function
FUNCTION SHOW_BACKGROUND:
         DRAWSPRITE BACKGROUND, 100, 100
ENDFUNCTION

Cheers,
P.
« Last Edit: 2012-Aug-15 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Hotshot

  • Mc. Print
  • *
  • Posts: 22
    • View Profile
Re: Functions ?
« Reply #2 on: 2012-Aug-15 »
Thanks Poetronic  =D   I love Functions because that where I can break small code down into :)

Offline Why0Why

  • Mc. Print
  • *
  • Posts: 1
    • View Profile
Re: Functions ?
« Reply #3 on: 2012-Aug-15 »
Hey Hotshot, guess we were reading the same thread on the Blitz forums ;)  I had bought GL years ago when they first came out with iPhone support and never really used it much.  I moved over to Corona for awhile and then I have been using Monkey.  Like you, just thought I would give it another shake.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2792
    • View Profile
Re: Functions ?
« Reply #4 on: 2012-Aug-15 »
Welcome back, dont hesitate to ask any questions if need be.  :)
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Hotshot

  • Mc. Print
  • *
  • Posts: 22
    • View Profile
Re: Functions ?
« Reply #5 on: 2012-Aug-15 »
Thanks guys :)