2019-01-08 01:41:54 -08:00
|
|
|
# World Action Script (was)
|
|
|
|
Version: 1
|
2019-01-08 04:17:35 -08:00
|
|
|
Licenses: code: LGPL-2.1, media: CC BY-SA-4.0
|
2019-01-07 13:07:54 -08:00
|
|
|
|
|
|
|
in game programing, not in lua
|
|
|
|
|
2019-01-09 01:04:12 -08:00
|
|
|
---
|
2019-01-07 13:07:54 -08:00
|
|
|
|
2019-01-09 04:02:17 -08:00
|
|
|
|
|
|
|
<details><summary>DATA TYPES</summary>
|
|
|
|
|
2019-01-12 13:52:08 -08:00
|
|
|
|Type|examples|examples|examples|examples|examples|examples|
|
|
|
|
|---------------|-----------|-|-|-|-|-|
|
2019-01-09 01:18:12 -08:00
|
|
|
|bool |true |false
|
|
|
|
|number |0 |123.456 |-5
|
|
|
|
|string |"asd 134"
|
2019-01-12 13:50:55 -08:00
|
|
|
|var |string |number |function |var |bool|table|
|
2019-01-09 01:18:12 -08:00
|
|
|
|function |pos(1 2 a)
|
2019-01-12 13:46:19 -08:00
|
|
|
|symbol |! |(nil) |? (username)|
|
2019-01-09 04:02:17 -08:00
|
|
|
</details>
|
2019-01-07 13:07:54 -08:00
|
|
|
|
2019-01-09 04:02:17 -08:00
|
|
|
<details><summary>VARIABLES</summary>
|
2019-01-09 03:53:24 -08:00
|
|
|
a variable can only be set to 1 thing at time
|
2019-01-07 13:07:54 -08:00
|
|
|
|
2019-01-09 03:53:24 -08:00
|
|
|
|example |-|-|-|-|-|-|
|
|
|
|
|---------------|-|-|-|-|-|-|
|
|
|
|
|varname |a variable|
|
|
|
|
|var_aa = |set variable value|
|
|
|
|
|another_var = |"string"| 123.54| false |var |function()| symbol|
|
|
|
|
|vara = varb |set to another var|
|
2019-01-12 13:50:08 -08:00
|
|
|
|vara.b = |set as table|
|
2019-01-14 13:52:25 -08:00
|
|
|
|vara.1 = |variable index 1 set, eg in lua: vara[1] (limeted to root variable)
|
2019-01-12 13:50:08 -08:00
|
|
|
|event.msg.item |item from event message|
|
2019-01-09 03:53:24 -08:00
|
|
|
|a += 5 |add 5
|
2019-01-09 04:03:47 -08:00
|
|
|
|a -= 4 |sub 4
|
2019-01-09 03:53:24 -08:00
|
|
|
|a *= 98 |multiply
|
|
|
|
|a /= 2 |divide
|
2019-01-09 04:03:47 -08:00
|
|
|
|a != |a = nil (used becaouse you can't set a=nll )
|
2019-01-09 04:02:17 -08:00
|
|
|
|
2019-01-09 00:58:13 -08:00
|
|
|
note the character "-" can mess if it is written together another symbol
|
2019-01-09 00:48:15 -08:00
|
|
|
|
2019-01-09 01:04:12 -08:00
|
|
|
**add a node, could be**
|
2019-01-09 01:10:02 -08:00
|
|
|
```lua
|
2019-01-09 00:58:13 -08:00
|
|
|
node.add(pos( -1 2 34) "default:dirt")
|
2019-01-09 01:10:02 -08:00
|
|
|
```
|
2019-01-09 01:04:12 -08:00
|
|
|
**and...**
|
2019-01-09 01:10:02 -08:00
|
|
|
```lua
|
2019-01-09 00:58:13 -08:00
|
|
|
c = 34
|
|
|
|
a = pos(1 2 c)
|
|
|
|
dirt="default:dirt"
|
|
|
|
node.add(a dirt)
|
2019-01-09 01:10:02 -08:00
|
|
|
```
|
2019-01-20 13:37:27 -08:00
|
|
|
you can use "return" to break the currently run
|
2019-01-09 04:02:17 -08:00
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-13 01:48:08 -08:00
|
|
|
<details><summary>Saving/load</summary>
|
2019-01-13 01:30:55 -08:00
|
|
|
Everthing in the "save" variable/table will be automacly saved and loaded, eg:
|
|
|
|
|
|
|
|
```lua
|
|
|
|
save.a="asd"
|
|
|
|
save.unit_users.singleplayer.lpos=get.pos()
|
|
|
|
|
|
|
|
if(save.a=="asd")
|
|
|
|
..code..
|
|
|
|
end
|
|
|
|
```
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details><summary>Events</summary>
|
|
|
|
Any reasons to the script on the unit is running will be able in the "event" variable, eg: event.type
|
|
|
|
|
2019-01-13 01:47:14 -08:00
|
|
|
|event |type |channel|from_channel|msg|
|
|
|
|
|-------------|-------------|-------|------------|---|
|
2019-01-20 13:41:58 -08:00
|
|
|
|run by gui |"gui_run" |✖ |✖ |✖
|
2019-01-13 01:47:14 -08:00
|
|
|
|timer |"timer" |✖ |✖ |✖
|
|
|
|
|wire |"wire" |✔ |✔ |✔
|
|
|
|
|digilines |"digiline" |✔ |✖ |✔
|
|
|
|
|msesecons on |"mesecon on" |✖ |✖ |✖
|
|
|
|
|meseconns off|"mesecon off"|✖ |✖ |✖
|
2019-01-20 13:43:14 -08:00
|
|
|
|pipeworks |"pipeworks" |✖ |✖ |✔ (item,count)
|
2019-01-13 01:30:55 -08:00
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-09 04:02:17 -08:00
|
|
|
|
|
|
|
<details><summary>IF</summary>
|
|
|
|
|
2019-01-09 01:10:02 -08:00
|
|
|
```lua
|
2019-01-08 01:41:54 -08:00
|
|
|
if(a==b)
|
|
|
|
..code..
|
|
|
|
endif
|
2019-01-09 01:10:02 -08:00
|
|
|
```
|
|
|
|
```lua
|
2019-01-08 01:41:54 -08:00
|
|
|
if(1=="asd" or a~=b and 87.3>=c nor a<=3 not "aasd"==!)
|
|
|
|
..code..
|
|
|
|
elseif(b==!)
|
|
|
|
..code..
|
|
|
|
elseif(b~=a not c<b)
|
|
|
|
..code..
|
|
|
|
else
|
|
|
|
..code..
|
|
|
|
endif
|
2019-01-09 01:10:02 -08:00
|
|
|
```
|
2019-01-09 04:02:17 -08:00
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details><summary>FOR LOOP</summary>
|
|
|
|
|
2019-01-09 01:10:02 -08:00
|
|
|
```lua
|
2019-01-09 04:06:44 -08:00
|
|
|
start_n = 3
|
|
|
|
end_n = 100
|
|
|
|
for(start_n end_n)
|
2019-01-09 01:10:02 -08:00
|
|
|
..code...
|
|
|
|
next
|
|
|
|
```
|
2019-01-09 04:06:44 -08:00
|
|
|
max loops is 1000, dont use negative values
|
2019-01-20 13:37:27 -08:00
|
|
|
use "break" to breat the loop
|
2019-01-09 04:02:17 -08:00
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details><summary>REGISTRY FUNCTIONS</summary>
|
2019-01-09 01:10:02 -08:00
|
|
|
|
|
|
|
```lua
|
2019-01-08 01:41:54 -08:00
|
|
|
was.register_function("name"{
|
|
|
|
info="", --function description
|
|
|
|
privs={}, --required privileges, eg (kick=true,server=true)
|
|
|
|
action=function(arg1,arg2...) --function
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
})
|
2019-01-09 01:10:02 -08:00
|
|
|
```
|
|
|
|
```lua
|
2019-01-08 01:41:54 -08:00
|
|
|
was.register_function("name"{
|
2019-01-09 04:10:58 -08:00
|
|
|
packed=true, --inputs all args as table
|
2019-01-08 01:41:54 -08:00
|
|
|
action=function(args)
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
})
|
2019-01-09 01:10:02 -08:00
|
|
|
```
|
2019-01-09 04:02:17 -08:00
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details><summary>REGISTRY SYMBOLS</summary>
|
|
|
|
|
2019-01-08 01:41:54 -08:00
|
|
|
a symbol are called while calling a function or setting a var
|
2019-01-09 01:10:02 -08:00
|
|
|
```lua
|
2019-01-08 01:41:54 -08:00
|
|
|
was.register_symbol("#",function(),"info"
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
})
|
2019-01-09 01:10:02 -08:00
|
|
|
```
|
2019-01-09 04:02:17 -08:00
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<details><summary>USERDATA</summary>
|
2019-01-07 13:07:54 -08:00
|
|
|
|
2019-01-08 01:41:54 -08:00
|
|
|
The user's information are stored in the global variable "was.userdata"
|
|
|
|
but is only able while the function / variables are active.
|
|
|
|
|
2019-01-09 04:11:35 -08:00
|
|
|
|variable / function|description |
|
|
|
|
|-------------------|------------|
|
2019-01-09 04:10:58 -08:00
|
|
|
|was.iuserdata(index) |return indexed active data|
|
|
|
|
|was.ilastuserdata() |return last index|
|
|
|
|
|was.userdata.data |the active line|
|
|
|
|
|was.userdata.index |index of active line|
|
|
|
|
|was.userdata.function_name |name of active function|
|
|
|
|
|was.userdata.name |user's name|
|
|
|
|
|was.userdata.var |all active variabbles|
|
2019-01-09 04:20:52 -08:00
|
|
|
|was.userdata.error |crach and send text message|
|
2019-01-09 04:02:17 -08:00
|
|
|
</details>
|