Sub rmm
dd= LDDialogs.LastRightClickMenuItem
if dd>0 Then
Controls.SetTextBoxText(pgm, LDText.Replace ( deff[dd],"!",CR)) ' Nonki: ESLText.CRLF
Else
ib=Dialogs.AskForTextLine ("Name (x=exit, l=load, s=save):","New Menu Item")
If ib="s" Then
' The following line could be harmful and has been automatically commented.
' File.WriteContents ("f:\defs.txt",deff)
' The following line could be harmful and has been automatically commented.
' File.WriteContents ("f:\defm.txt",dmt)
Dialogs.ShowMessageBox("Saved ok.","Menu","OK","Information")
elseIf ib="l" Then
' The following line could be harmful and has been automatically commented.
' deff=File.ReadContents ("f:\defs.txt")
' The following line could be harmful and has been automatically commented.
' dmt=File.ReadContents ("f:\defm.txt")
Dialogs.ShowMessageBox("Load ok.","Menu","OK","Information")
LDDialogs.AddRightClickMenu(dmt,"")
elseIf ib<>"x" then
li= LDText.Split (Text.ConvertToUpperCase(src),CR)
att=""
For t=1 To Array.GetItemCount (li)
att=att+li[t]+"!"
endfor
deff[dmm]= att
dmt[dmm]=ib
dmm=dmm+1
LDDialogs.AddRightClickMenu(dmt,"")
While "True"
If rst=1 Then
src = Controls.GetTextBoxText(pgm)
For i = 1 To 1000 ' Nonki: GraphicsWindow.Clear()
Shapes.Remove("_turtleLine" + i)
EndFor
rst=0
Goto rrr
elseIf clicked Then
src = Controls.GetTextBoxText(pgm)
If Text.GetSubText(src,1,1)="{" or Text.GetSubText(src,1,1)="#" then
If Text.GetSubText(src,1,1)="#" then
dbg="True"
Else
dbg="False"
endif
line= LDText.Split (Text.ConvertToUpperCase(src),CR) ' Nonki: ESLText.CRLF
rr=MathPlus.ToNumber ( text.GetSubTextToEnd(line[1],2))
nLines =Array.GetItemCount (line)
For tt=1 To rr
For i = 2 To nLines
linee=line[i]
DoLine()
EndFor
EndFor
Sub OnButtonClicked
If Controls.LastClickedButton=c2 then
rst=1
else
clicked = "True"
endif
EndSub
Sub Run
line= LDText.Split (Text.ConvertToUpperCase(src),CR)
if dbg then
TextWindow.WriteLine (line)
endif
l = 1 ' level
nLines =Array.GetItemCount (line)
For i = 1 To nLines
linee=line[i]
DoLine()
EndFor
EndSub
Sub DoLine
' param line - array of command lines
' param i - index to do for the line
GraphicsWindow.PenColor=LDColours.HSLtoRGB(math.Remainder (ch,360) ,0.9,0.4)
ch=ch+1
If Text.StartsWith(linee, "F") Then
distance = Text.GetSubTextToEnd(linee, 3)
Turtle.Move(math.Floor (distance*sc))
if dbg then
TextWindow.WriteLine(math.Floor (distance*sc))
endif
ElseIf Text.StartsWith(linee, "S") Then
sc=sc* Text.GetSubTextToEnd(linee, 3)
If sc=0 then
sc=1
EndIf
ElseIf Text.StartsWith(linee, "U") Then
Turtle.PenUp()
ElseIf Text.StartsWith(linee, "D") Then
Turtle.PenDown()
ElseIf Text.StartsWith(linee, "R") Then
angle = Text.GetSubTextToEnd(linee, 3)
Turtle.Turn(angle)
ElseIf Text.StartsWith(linee, "L") Then
angle = -Text.GetSubTextToEnd(linee, 3)
Turtle.Turn(angle)
ElseIf Text.StartsWith(linee, "{") Then
b = Text.GetIndexOf(linee, "[")
count[l] = mathplus.ToNumber ( Text.GetSubText(linee, 2, b - 2))
iStart[l] = i + 1
iEnd[l] = nLines
nest = 0
if dbg then
TextWindow.WriteLine ("For #/b/e:"+l+"\"+count[l]+"# "+(i+1)+":"+nLines )
endif
For k = iStart[l] To nLines
'TextWindow.WriteLine(">>"+k)
If Text.StartsWith(line[k], "{") Then
nest = nest + 1
ElseIf Text.StartsWith(line[k], "]") Then
If nest = 0 Then
iEnd[l] = k - 1
k = nLines
Else
nest = nest - 1
EndIf
EndIf
EndFor
l = l + 1
if dbg then
TextWindow.WriteLine ("<:"+count[l - 1])
endif
For j = 1 To count[l - 1]
Stack.PushValue("local", j)
For i = iStart[l - 1] To iEnd[l - 1]
linee=line[i]
If dbg then
TextWindow.WriteLine (i+">>"+linee)
endif
DoLine()
EndFor
j = Stack.PopValue("local")
EndFor
l = l - 1
i = iEnd[l] + 1
EndIf
EndSub