SOLVED:Lua Syntax Help - 1.Guard Duty: Game Development 2

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 
        -- Else, move back to the starting position.

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)

Hi there,

I think there’s a bit of confusion. You only have to play in Lua because you started playing in Lua. At this time, you cannot change heroes or languages in the game dev or web dev levels.

If you want, you can email me your username (and explain the problem) and I can change it so you can play in JavaScript.

We only fully support JavaScript and Python. Levels are converted to Lua by volunteers and newer levels might not be converted yet. We do not recommend using Lua or CoffeeScript in CodeCombat or that reason.

The real answer is:

Contact and tell them you’re stuck in Lua in Game Dev 2. Give them your username so they can fix it for you.

But, for fixing Guard Duty directly, if you want to play it in Python instead, go here:

If you want to do it in JavaScript, go here:

That will force the level to load in that language. Then click “Restart” so you get the correct default code for that level (for that language).