Campaign with lua

For AI and campaign script related discussions and questions
Samowar
Trained
Trained
Posts: 42
Joined: 03 Jun 2009, 19:46

Campaign with lua

Post by Samowar »

This thread is for everyone replaying the campaign with the lua2 branch to test the lua scripts for the campaign and report any impressions and bugs.

-in alpha 2 ("power surge") there was a New Paradigm sensor standing around at the SE corner (where NP would attack from in alpha 6). Is this supposed to happen?

- in alpha 5 (where you first meet the new paradigm) and 6, the new paradigm seems strangely apathetic. In alpha 5, after I kill their commander, they don't come out of their castle anymore; they keep producing units, but these just stay inside and wait for me to storm the castle. In alpha 6, they're supposed to attack me from the southeast, but they just stand arrayed in their canyon and wait for me to come in and get them. Perhaps the latter has something to do with me killing their sensor in alpha 2. Note to self: replay with letting it live.
Attachments
What is it? Where does it come from?
What is it? Where does it come from?
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Campaign with lua

Post by Per »

As you play campaign with lua, you will notice some messages on stdout/stderr or stdout.txt/stderr.txt saying "stub: NNN", where NNN is some function name. This means function NNN is called but not yet ported. If you post the names of those functions here, I'll port them for you :-)
Samowar
Trained
Trained
Posts: 42
Joined: 03 Jun 2009, 19:46

Re: Campaign with lua

Post by Samowar »

Samowar wrote:Perhaps the latter has something to do with me killing their sensor in alpha 2. Note to self: replay with letting it live.
OK, it doesn't.

@stubs:
stub: groupMember
stub: setGroupSecondary
stub: _
stub: showConsoleText
stub: flushConsoleMessages
stub: randomiseSeed
stub: initAllNoGoAreas
stub: addDroidToMissionList

As for the apathetic AI in mission 5, I've attached a savegame. See for yourself.

EDIT: Some other strange things happened in mission 5:
- The research facility inside then NP base looked strangely unfinished.
- When I destroyed the factory, an artefact appeared - at the site of the former research facility.
Attachments
unfinished repair facility
unfinished repair facility
magical remote item drop
magical remote item drop
apathetic.tgz
AI sits around and waits to be killed
(178.09 KiB) Downloaded 374 times
Safety0ff
Trained
Trained
Posts: 397
Joined: 18 Jul 2009, 23:23

Re: Campaign with lua

Post by Safety0ff »

Thank you for your reports, please don't stop! :D
They are really helpful for furthering development on the lua branch.
Samowar
Trained
Trained
Posts: 42
Joined: 03 Jun 2009, 19:46

Re: Campaign with lua

Post by Samowar »

With r9783:
error |06:29:16: [luaWZ_dofile] loading Lua file: script/data/cam1a-c_logic.lua:313: ')' expected near '['
error |06:29:16: [report]
script/glue.lua:79: failed loading file
stack traceback:
[C]: in function '__dofile'
script/glue.lua:79: in function 'dofile'
script/data/cam1a-c.lua:206: in main chunk
AI is still apathetic.

EDIT: Perhaps it's no error at all; I thought the AI was to attack immediately at the start of alpha 6 and devastate the southern part of the map, but reading the walkthrough I realize it could well be they wait for some minutes. If I attack them, they head straight for my HQ.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Campaign with lua

Post by Per »

error |06:29:16: [luaWZ_dofile] loading Lua file: script/data/cam1a-c_logic.lua:313: ')' expected near '['
When do you see this error? There seems to be a conversion error there, since a variable at that line got '_' added to it for no good reason I could see.
gerard_
Trained
Trained
Posts: 71
Joined: 02 Nov 2006, 19:56

Re: Campaign with lua

Post by gerard_ »

Per wrote:
error |06:29:16: [luaWZ_dofile] loading Lua file: script/data/cam1a-c_logic.lua:313: ')' expected near '['
When do you see this error? There seems to be a conversion error there, since a variable at that line got '_' added to it for no good reason I could see.
It's an conversion error, the variable should be checked in the function itself. It's one of the weirder things of the old script system. I'm working on it now.
dmkp
Trained
Trained
Posts: 182
Joined: 08 Jan 2010, 20:50
Location: UK
Contact:

Re: Campaign with lua

Post by dmkp »

What's "lua"?
User avatar
lav_coyote25
Professional
Professional
Posts: 3434
Joined: 08 Aug 2006, 23:18

Re: Campaign with lua

Post by lav_coyote25 »

dmkp wrote:What's "lua"?

http://www.lua.org/about.html
Samowar
Trained
Trained
Posts: 42
Joined: 03 Jun 2009, 19:46

Re: Campaign with lua

Post by Samowar »

Samowar wrote:I suppose this hasn't anything to do with lua, probably it was a bug that was there when trunk was merged into lua and has been corrected since in trunk. I didn't manage to find that changeset, however.
Found it. Ironically, it is the very changeset directly after trunk was merged into lua...

EDIT: Arrgh, edited instead of quoted. The original contents of the post were as follows.

- Repair Facility also looks strange when built by myself. Not the fault of lua per se. See above

- AI being apathetic in alpha 6 is definitely lua's fault; loading the start-of-mission-savegame in trunk starts an immediate attack.

Would it be possible for someone to merge trunk into lua again in svn? and wouldn't it make sense to include the .lua scripts into svn too?
Samowar
Trained
Trained
Posts: 42
Joined: 03 Jun 2009, 19:46

Re: Campaign with lua

Post by Samowar »

Samowar wrote:- AI being apathetic in alpha 6 is definitely lua's fault; loading the start-of-mission-savegame in trunk starts an immediate attack.
Hm... somehow the strike team never gets assembled, although it's all there in the script. Debugging with "break grpJoin if (psDroid->player==1)" shows suspiciously little activity at the start of the game when loading the end-mission-savegame (to be exact: Some Mortars are added to a group, but not a single Rocket-Bug).

btw: This error always crops up at loading a game:

error |06:46:17: [scrRandomiseSeed] A script is trying to set the random seed with srand(). That just doesn't make sense.

Commanders work now; they used not to which was in my post I inadvertedly deleted/edited and I forgot to restore that part.
Samowar
Trained
Trained
Posts: 42
Joined: 03 Jun 2009, 19:46

Re: Campaign with lua

Post by Samowar »

Samowar wrote:Hm... somehow the strike team never gets assembled, although it's all there in the script.
...and now I know why. At least partially. Somehow, when the second team (i.e. the rocket-bugs) is about to be assembled, luaWZObj_checkgroup reaches the following line:

Code: Select all

1760    luaL_error(L, "argument %d is not a group (not even a table)", pos);
Unfortunately, luaL_error doesn't seem to print anything on stderr/stdout, much less stop execution; I had to single-step through the whole business with gdb.

I don't know how this was originally intended, but wouldn't it be better to handle even errors in functions which were called from lua scripts with "Assert or return"? That way at least we'd know where the script fails.
Samowar
Trained
Trained
Posts: 42
Joined: 03 Jun 2009, 19:46

Re: Campaign with lua

Post by Samowar »

Is anyone listening at all? Seems I'm the only one to post here in recent times.

Anyway, I've fixed some things to make scripts better debuggable (whose idea was it to throw out the backtraces in event.lua? You effectively "swallow" all script errors) and found the direct cause for the script error in alpha 6. However, as I now have script error output, I've discovered a huge flaw: Lua arrays are 1-based, so some of the converted code will attempt to read the zeroeth index, which is most probably not initialized. Example:

Code: Select all

script/data/cam1c_logic.lua:1002: attempt to index field '?' (a nil value)
stack traceback:
        script/data/cam1c_logic.lua:1002: in function <script/data/cam1c_logic.lua:978>
        (tail call): ?
        [C]: in function 'xpcall'
        script/version.lua:185: in function 'call_with_backtrace'
        script/event.lua:130: in function <script/event.lua:123>
script/data/cam1c_logic.lua:894: argument 1 is not a group (not even a table)
stack traceback:
        [C]: in function 'groupCountMembers'
        script/data/cam1c_logic.lua:894: in function <script/data/cam1c_logic.lua:890>
        (tail call): ?
        [C]: in function 'xpcall'
        script/version.lua:185: in function 'call_with_backtrace'
        script/event.lua:130: in function <script/event.lua:123>
EDIT: Seems I've opened a box of Pandora...

Code: Select all

attempt to yield across metamethod/C-call boundary                                                  
stack traceback:                                                                                    
        [C]: in function 'yield'                                                                    
        script/version.lua:177: in function 'pause'                                                 
        script/data/cam1a_logic.lua:426: in function <script/data/cam1a_logic.lua:424>              
        (tail call): ?                                                                              
        [C]: in function 'xpcall'                                                                   
        script/version.lua:185: in function 'call_with_backtrace'                                   
        script/event.lua:130: in function <script/event.lua:123>
Seems the pause() function doesn't really work. You can however achieve the same effect with the following contraption:

Code: Select all

function scavAttack2delayed()
	deactivateEvent(scavAttack2delayed)
	conditionalEvent(removeObj1, "droidInRange(player, 4928, 6592, 5 * 128)", 2.0)
	addMessage(MissionBrief2, MISS_MSG, player, true)
	addMessage(obj1Msg, PROX_MSG, player, false)
	orderGroupLoc(scavGroup, DORDER_SCOUT, 2100, 6700)
end

function scavAttack2() -- event at line 556
	playSound(incomingSnd, player)
	delayedEvent(scavAttack2delayed, 20/10.0)
	deactivateEvent(scavAttack2)
end
conditionalEvent(scavAttack2, "droidInArea(player, 2496, 6080, 4928, 7232)", 0.5)
And now a question to the devs: Do you plan on eventually writing an improved script converter that fixes all those flaws automatically? Because in that case I needn't bother fixing the scripts manually. If not, however, perhaps it would make sense to put the lua scripts under version control.

Fixes for script debugging attached
Attachments
debuglua.diff
Restore backtrace ability of scripts.
(1.23 KiB) Downloaded 357 times
debuglib.diff
Make lib/lua/ debuggable. Proved unnecessary in the end, but never hurts (I hope)
(896 Bytes) Downloaded 337 times
User avatar
Buginator
Professional
Professional
Posts: 3285
Joined: 04 Nov 2007, 02:20

Re: Campaign with lua

Post by Buginator »

Samowar wrote:Is anyone listening at all? Seems I'm the only one to post here in recent times.
Yes, people are listening, it is just we are all rather busy (with real world), and the forums are pretty much the last place anyone looks, because of time constraints.

Will try to get a answer for you, the next time I see Gerard.

If you think the converter scripts are broken, it is best to open a ticket about that, so it will get noticed, the other devs tend to check tickets before forums.
and it ends here.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Campaign with lua

Post by Per »

Samowar wrote:Is anyone listening at all?
Yes, with great interest.
Samowar wrote:However, as I now have script error output, I've discovered a huge flaw: Lua arrays are 1-based, so some of the converted code will attempt to read the zeroeth index, which is most probably not initialized.
If you look at the lua code converted from VLO files, they use zero-indexed arrays (which are legal in lua, but not exactly encouraged or recommended) but at great cost to code readability. So we should probably change this.
Post Reply