### Author Topic: Apple Dolphin  (Read 2570 times)

#### Cosmo

• Guest
##### Apple Dolphin
« on: February 03, 2014, 12:49:45 AM »
Hello,

« Last Edit: December 12, 2014, 05:01:25 PM by PeterMaria »

#### Cybermonkey

• Posts: 0
##### Re: Apple Dolphin
« Reply #1 on: February 03, 2014, 04:20:21 PM »
Maybe this can help: http://lua-users.org/lists/lua-l/2009-03/msg00439.html
Recursion in Lua.

#### Tomaaz

• Guest
##### Re: Apple Dolphin
« Reply #2 on: February 03, 2014, 11:23:54 PM »
Hello Markus,

EGSL knows no recursion ?

Of course, you can use recursion in EGSL, because you can use recursion in Lua (is there any serious programming language in which using recursion is not possible?). The problem in your example is variable scope. In Lua variables defined inside a function are by default global, while in other languages they may be by default local. You need to remember that when you copy/paste the code written in other language. Just add local to x2 and y2 and it'll be working properly.

Code: [Select]
`openwindow(600,600,0,"Tree")backcolor(240,255,255)function tree(x1, y1, a, d)   if d ~= 0 then      local x2 = x1 + math.cos(math.rad(a)) * d * 10      local y2 = y1 + math.sin(math.rad(a)) * d * 10      color(170,108,0)      line(x1, y1, x2, y2)      redraw()      tree(x2, y2, a - 20, d - 1)      tree(x2, y2, a + 20, d - 1)   endendtree(300, 550, -90, 9)redraw()inkey() `
« Last Edit: February 03, 2014, 11:28:10 PM by Tomaaz »

#### Tomaaz

• Guest
##### Re: Apple Dolphin
« Reply #3 on: February 04, 2014, 01:03:01 AM »