I have to go back to the start of the campaign and play through in Lua in order to learn the syntax and the language.
Developers: If you could add a note into the Hints for players that have run through the campaign just on python and once they’ve reached , game development 2, to say “If you haven’t had learnt LUA, please go back to the start and play the levels in LUA to learn the syntax etc.”
I am having trouble with using Lua for level 1.Guard Duty of Game development 2.
My first question is -
Do we have to play this level in Lua or is it a bug that my game has set the level in Lua?
I’ve had to do a bit of googling to find out that you have to write [if (variable) then]
The game hasn’t taught us any of the syntax for Lua so how are we supposed to complete this level?
I am happy to research but the game should point us in the right direction.
So far … I’ve added the soldier, wrote code to attack the enemy and wrote code to move back to the starting position. I don’t know if the syntax is right. I’ve checked in the hints and the methods and that is of no help.
When I press Test Level it states “soldierLogic()” is not defined.
-- Add a soldier to the level to prevent ogres from crossing the path. -- Command the soldier using an event handler function. function soldierLogic() -- Fill in the code for the soldier's actions here. -- Remember to use 'soldier' instead of 'hero'! while true do enemy = soldier:findNearestEnemy() -- Attack the enemy, if the enemy exists. if enemy then soldier:attack(enemy) -- Else, move back to the starting position. else soldier:moveXY(42,48) end end game:spawnXY("soldier", 42,48) -- This assigns your spawned unit to the soldier variable. soldier = game:spawnXY("soldier", 42, 48) -- This says to run the soldierLogic function when the soldier is spawned. soldier:on("spawn", soldierLogic) end