Calling Outside Variables Within Functions?

Post Reply
the_wesley_watkins
Posts: 42
Joined: Wed Jul 29, 2015 3:53 pm
My devices: Ipad
Iphone

Calling Outside Variables Within Functions?

Post by the_wesley_watkins »

Is there anyway to use a variable created outside of a function within a function?


Such as:

Code: Select all

GRAPHICS
GRAPHICS CLEAR 0.34,0.34,0.34

x = 25
y = 25
w = 10
h = 10

DEF drawRect

	FOR COUNT = 1 TO 5
		DRAW RECT x * COUNT, y SIZE w, h
	NEXT COUNT

END DEF


CALL drawRect

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Calling Outside Variables Within Functions?

Post by Mr. Kibernetik »

Yes, of course.

Use null scope name when using global (defined in main program body) variables:

Code: Select all

GRAPHICS
GRAPHICS CLEAR 0.34,0.34,0.34

x = 25
y = 25
w = 10
h = 10

DEF drawRect

   FOR COUNT = 1 TO 5
      DRAW RECT .x * COUNT, .y SIZE .w, .h
   NEXT COUNT

END DEF


CALL drawRect

Post Reply