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