Skip to content

Commit

Permalink
update web exemples
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythux committed May 4, 2021
1 parent 91b2a55 commit 77b7f1c
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 327 deletions.
2 changes: 1 addition & 1 deletion tests/test_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def assertCompilationException(code, exceptionSubStr):
'control shootp block1 0 0 0 0 6': "line 1, instruction 'control' require 5 arguments, 6 given",
}
instrUcontrol = {
'ucontrol': "line 1, instruction 'ucontrol', require keyword, must be on of: ['idle', 'stop', 'move', 'approach', 'pathfind', 'target', 'targetp', 'itemdrop', 'itemtake', 'paydrop', 'paytake', 'flag', 'mine', 'build', 'getblock', 'within', 'boost']",
'ucontrol': "line 1, instruction 'ucontrol', require keyword, must be on of: ['idle', 'stop', 'move', 'approach', 'pathfind', 'target', 'targetp', 'itemDrop', 'itemTake', 'payDrop', 'payTake', 'flag', 'mine', 'build', 'getBlock', 'within', 'boost']",
'ucontrol 4': "line 1, instruction 'ucontrol', '4' is not a valide keyword, must be on of:",
'ucontrol move 0 0 0 0 0 6': "line 1, instruction 'ucontrol' require 5 arguments, 6 given",
}
Expand Down
144 changes: 0 additions & 144 deletions tests/webExemples/botForLoop.code

This file was deleted.

36 changes: 7 additions & 29 deletions tests/webExemples/forLoop.code
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@

// will print "1 2 3 ", "2 3 4 ", "3 4 5 ", ...
import time
list = [a, b]

list = [a, b, c]

set a 1
set b 2
set c 3
for el in list
set el 1

#ref loop
for x in list
op add x x 1
print x
print " "


time.wait(1)
printflush message1
printflush message
jump loop


----------------------


set a 1
set b 2
set c 3
set b 1
op add a a 1
print a
print " "
op add b b 1
print b
print " "
op add c c 1
print c
print " "
set tmp2 1
op add returnAddress-time-wait @counter 1
jump 18 always true true
printflush message1
jump 3 always true true
end
set tmp1 @time
op mul tmp2 tmp2 1000
op add tmp3 tmp1 tmp2
jump 21 greaterThanEq tmp3 @time
set @counter returnAddress-time-wait
printflush message
jump 2 always true true
83 changes: 16 additions & 67 deletions tests/webExemples/function.code
Original file line number Diff line number Diff line change
@@ -1,77 +1,26 @@

set message message1

print "hi !, what is the value of x and y ?"
printflush message
wait(1.6) // wait 1.6 secondes

set x @thisx
set y @thisy
print "x:"
print x
print " y:"
print y
printAndWait("\n and now we will wait two secondes", message)

printAndWait("2s have passed !", message)

set tmp2 "we could also use tmpX variables freely"
printAndWait(tmp2, message)


printAndWait(msg, messageX)
show(msg, m)
print msg
printflush messageX
wait(2)


wait(secondes)
set timestamps @time
op mul secondes secondes 1000
op add timestampsToWait timestamps secondes
printflush m

// can jump on himself, not possible on game UI
#ref waiting
jump waiting timestampsToWait >= @time
set m message1
show("hi!", m)
show("how are you", m)


----------------------


set message message1
print "hi !, what is the value of x and y ?"
printflush message
set tmp5 1.6
op add returnAddress-None-wait @counter 1
jump 26 always true true
set x @thisx
set y @thisy
print "x:"
print x
print " y:"
print y
set tmp1 "\n and now we will wait two secondes"
set tmp3 message
op add returnAddress-None-printAndWait @counter 1
jump 31 always true true
set tmp1 "2s have passed !"
set tmp3 message
op add returnAddress-None-printAndWait @counter 1
jump 31 always true true
set tmp2 "we could also use tmpX variables freely"
set tmp1 tmp2
set tmp3 message
op add returnAddress-None-printAndWait @counter 1
jump 31 always true true
set m message1
set tmp1 "hi!"
set tmp2 m
op add returnAddress-None-show @counter 1
jump 10 always true true
set tmp1 "how are you"
set tmp2 m
op add returnAddress-None-show @counter 1
jump 10 always true true
end
set tmp4 @time
op mul tmp5 tmp5 1000
op add tmp6 tmp4 tmp5
jump 29 greaterThanEq tmp6 @time
set @counter returnAddress-None-wait
print tmp1
printflush tmp3
set tmp5 2
op add returnAddress-None-wait @counter 1
jump 26 always true true
set @counter returnAddress-None-printAndWait
printflush tmp2
set @counter returnAddress-None-show
72 changes: 17 additions & 55 deletions tests/webExemples/if.code
Original file line number Diff line number Diff line change
@@ -1,61 +1,23 @@

// a code to fix to a screen, a message box and a power node
//
// it will give a color depending of electicity net production

sensor in node1 @powerNetIn
sensor out node1 @powerNetOut

// get net power produced with:
op sub net in out
op floor net net out // floor number to be always humain readable
print "power: "
print net
printflush message1
// put all printed message ("power: " + net) in message1
// (need a message box liked to processor to see it)

// color to corresponding power produced:

if net >= 1200
// green color
draw clear 0 1000 0 0 0 0
elif net >= 500
// yellow
draw clear 1000 1000 0 0 0 0
set x 1
#ref loop
if x < 4
op add x x 1
elif x == 4
print x
else
// red
draw clear 1000 0 0 0 0 0

// draw the choosen color on display1
drawflush display1

// wait a short time to avoid disturbing blink colors change

set wait 0
#ref waiting
op add wait wait 1
jump waiting wait <= 200
end
jump loop


----------------------


sensor in node1 @powerNetIn
sensor out node1 @powerNetOut
op sub net in out
op floor net net out
print "power: "
print net
printflush message1
jump 13 greaterThanEq net 1200
jump 11 greaterThanEq net 500
draw clear 1000 0 0 0 0 0
jump 14 always true true
draw clear 1000 1000 0 0 0 0
jump 14 always true true
draw clear 0 1000 0 0 0 0
drawflush display1
set wait 0
op add wait wait 1
jump 16 lessThanEq wait 200
set x 1
jump 7 lessThan x 4
jump 5 equal x 4
end
jump 8 always true true
print x
jump 8 always true true
op add x x 1
jump 1 always true true
Loading

0 comments on commit 77b7f1c

Please sign in to comment.