MachineCraft

MachineCraft

評價次數不足
Introduction to Lua Scripting
由 pringding 發表
Introduction to Lua Programming in MachineCraft
   
獎勵
加入最愛
已加入最愛
移除最愛
1
Lua scripting in this game is quite a hidden feature. There are AI bots in the _samples folder that show what Lua scripting can do, but they don't have guides yet. If you've ever seen a player in-game with a green name, that means that they're using a Lua script to control their bot automatically.
2
If you're completely new to the Lua programming language (or to programming in general) I recommend you watch the first 10 minutes of this video: https://www.youtube.com/watch?v=iMacxZQMPXs
It goes over some of the basic things you'll need to know when making your own scripts.
3
The best place to start is with the AI machines in the _samples folder, the most basic is "AI_Mortar". Try out the bot in Test mode (don't press any buttons to control it, let it work on it's own). There should be some white text in the top-right corner, this is from the Print function in the script, you can use this to display debug information so that if something goes wrong in your script, you can see what went wrong. The game will also tell you about any errors in your script by displaying a yellow message in the top-left corner.
4
After you've tried out the AI bot, go to the _scripts folder (should be located here: C:\Program Files (x86)\Steam\steamapps\common\MachineCraft\UserData\_scripts). This is where all of the default scripts are and it is where you should put the scripts that you make. Open the file named "mortar.txt" (best program to use is Notepad++, but Notepad should do) and look at the code past "function_update()". This is where you should put most of your code to control your machine.
5
In my next guide I will explain how you can use the different functions avaliable to control your machine. There is a document which containing explanations of the code (unfinished) here: https://docs.google.com/document/d/1k0a744BAum2PlR5GVfO8Fg6ZNIakNhxZNutSeMlNrjY/edit?usp=sharing
If you have any questions just ask them in the comments.

*I haven't written a guide like this in months so sorry if it isn't great
9 則留言
MJRAHOLE 2017 年 4 月 17 日 下午 7:31 
@Turret problems

Workshop Items lack an AI Script, because we are builders, not AI designers.
Turret problems 2016 年 9 月 17 日 上午 11:36 
where are the scripts workshop items use?
RA2lover 2016 年 8 月 21 日 上午 3:37 
That document is also outdated. Luaスクリプト<kanji i've never managed to learn>.txt now makes mentions of drawing-related functions:
[list]
[*]SetLogicalScreenHeight(float height)
[*]DrawLine2D(Color color [, Vector2 vtx1, Vector2 vtx2])
[*]DrawLine2D(Vector2 vtx1, Vector2 vtx2)
[*]MakePattern2D(string name)
[*]DrawPattern2D(string name, Color color, Vector2 pos [, Vector2 scale])
[*]DrawGraph(string name [, float val , int num]?, Color color, Vector2 pos, Vector2 scale
[*]DrawLine3D(Color color [, Vector3 vtx1, Vector3 vtx2])
[*]DrawLine3D(Vector3 vtx1, Vector3 vtx2)
[*]MakePattern3D(string name)
[*]DrawPattern3D(string name, Color color, Vector3 pos [, Vector3 scale])
[/list]

Can't really translate them because the file has mojibake issues, although it seems most of these seem to be straightforward to use.
Calen_Loki 2016 年 6 月 28 日 上午 6:05 
Turret problems 2016 年 6 月 24 日 下午 7:41 
nvm
Turret problems 2016 年 6 月 24 日 下午 7:39 
how do i use the scripts?
PanTurtle 2016 年 5 月 4 日 下午 10:46 
nv i realized how to make my machine how to use scripts
PanTurtle 2016 年 5 月 4 日 下午 10:33 
how do i make sure in the script that it is controling it in the txt? All i really want is to take the autofire script there and put it on my Aircraft Carrier