Functions

Post your coding questions such as 'how to' here.
Post Reply
Extra_Ammo

Functions

Post by Extra_Ammo »

How to make them? I know the main part.

Code: Select all

function nb(nbs)
 g = 0
 for fx = -1 to 1
  for fy = -1 to 1
   if grid(x,y) = nbs then g = g + 1
  next fy
 next fx
 nb() = g '  <--- I get an error here
end function
How do I return the value of the function?
Koodiapina
Forum Veteran
Posts: 2396
Joined: Tue Aug 28, 2007 4:20 pm

Re: Functions

Post by Koodiapina »

To Return values from function, use the return command.

Code: Select all

Return MyValue
And the value can be picked

Code: Select all

Var = MyFunction()
And an example:

Code: Select all

    Var = Double(2)
    Print Var
    Print Double(2)
    WaitKey 

    Function Double(Par)
        Return Par*2
    EndFunction 
Post Reply