A request for sample code(simple ai)

Hi, defolders. I’m a newbee in Lua, and after reading all documentations about it I can’t write my own code without some samples. If it’s not hard for you, could you, please, write me full code or a part, which will do(I shall change everything I need):
1)After I click on a button, all units (in some area near this button) must get to position of this button and disable it(first unit, which got there, disables it’s function in engaging other units, so they don’t move to button), then continue walking somewhere, .
2)Simple walking of units. They just walk in one direction and change it to opposite after touching the wall.
3)A script for the teleporter of units to another teleporter, which also changes their direction of movement.

That’s all, I think. I need these samples for better understanding of Lua, used in Defold. Thank you for your help.

I’m not convinced that ready made samples such as what you are requesting is the best way to learn something. I believe it’s better to follow tutorials or read manuals and experiment yourself to learn. But, with that said, we’re all different and learn stuff in different ways so I decided to take a break from the rather tedious work of creating some internal material for a presentation and create a sample project for you instead. I’ve done #1 and #2 and I have left #3 for you to figure out!

You can find the code here: https://github.com/britzl/publicexamples/tree/examples/simpleai
And an HTML5 demo here: http://britzl.github.io/publicexamples/simpleai/index.html (click to feed the zombie horde!)

8 Likes

Thanks to you for your work! Now I’ve figured out how to do most of the things I need.

1 Like