The Battle of Midway - Development Thread

I'm trying to be a good "resource requester" and actually finish this so everyone's help can be put to good use. I think I have the reactions more or less where I want them. I did get this error but seem to have cleared it by not allowing units to react from airfield terrain:

[CODE
D:\Test of Time\Scenario\Midway\events.lua:960: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
[C]: in function 'pairs'
D:\Test of Time\Scenario\Midway\events.lua:960: in upvalue 'reHomePayloadUnit'
D:\Test of Time\Scenario\Midway\events.lua:2336: in upvalue 'doOnActivateUnit'
D:\Test of Time\Scenario\Midway\events.lua:390: in upvalue 'runDoOnActivateUnit'
D:\Test of Time\Scenario\Midway\events.lua:1136: in function <D:\Test of Time\Scenario\Midway\events.lua:995>
[/CODE]

However I am having a major issue with getting the reinforcements to show up after loading a saved game. These had worked previously so I'm not sure what I messed up to change things. I have an idea (see below) but so you understand where I'm coming from, what I would do is play a hotseat game against myself and save, exit the game, and reload each player's turn to replicate a true PBEM.

On turn 1, each player is asked to choose where their reinforcements will arrive. On a random turn after that, reinforcements should show up. Yet, they don't. I never tested it this way until now so I don't know if they ever did. I'm attaching the entire scenario files in case someone can help me figure this last thing out. Aside from if I find any bugs, I think once this is done, I can release the scenario or at least public ally make it available for playtest, but this is a critical error, so if anyone can help I appreciate it.

Anyway... Since it functions with state I am hoping that the below would correct it:

You haven't 'linked' the state table to log.lua.

In Events.lua, you want something like
Code:
state.logState= state.logState or {}
log.linkState(state.logState)

Does this too all need to be referenced here:

Code:
civ.scen.onSave(function ()
    print(type(state))
  return civlua.serialize(state)
   -- return lualzw.compress(civlua.serialize(state))
end)

?

I have it here:

Code:
civ.scen.onLoad(function (buffer)

...

state.logState= state.logState or {}
log.linkState(state.logState)
end)

Any help would be greatly appreciated so I can wrap this one up. Thanks!
 

Attachments

  • Midway.zip
    2.2 MB · Views: 270
Does this too all need to be referenced here:

No, you don't need the reference in onSave.

I think I have the reactions more or less where I want them. I did get this error but seem to have cleared it by not allowing units to react from airfield terrain:

[CODE
D:\Test of Time\Scenario\Midway\events.lua:960: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
[C]: in function 'pairs'
D:\Test of Time\Scenario\Midway\events.lua:960: in upvalue 'reHomePayloadUnit'
D:\Test of Time\Scenario\Midway\events.lua:2336: in upvalue 'doOnActivateUnit'
D:\Test of Time\Scenario\Midway\events.lua:390: in upvalue 'runDoOnActivateUnit'
D:\Test of Time\Scenario\Midway\events.lua:1136: in function <D:\Test of Time\Scenario\Midway\events.lua:995>
[/CODE]

This error has nothing to do with reactions.

This is line 960
Code:
        for __,specification in pairs(secondaryAttackUnitTypes) do

The error is that there is no table secondaryAttackUnitTypes in this file. The problem is that a NON unit is trying to re-arm, but doesn't have a primary attack payload designation, so the code from OTR checks if the unit type is in the secondaryAttackUnitTypes table, which causes the error.

You can either remove the for loop (recommended) or put in a line after the primary attack definitions

secondaryAttackUnitTypes = {}

(easy, only 99% sure it will work).

Incidentally, the function reHomePayloadUnit seems to be defined twice in your code, though only the last one defined will be used in the program.

However I am having a major issue with getting the reinforcements to show up after loading a saved game. These had worked previously so I'm not sure what I messed up to change things. I have an idea (see below) but so you understand where I'm coming from, what I would do is play a hotseat game against myself and save, exit the game, and reload each player's turn to replicate a true PBEM.

On turn 1, each player is asked to choose where their reinforcements will arrive. On a random turn after that, reinforcements should show up. Yet, they don't. I never tested it this way until now so I don't know if they ever did. I'm attaching the entire scenario files in case someone can help me figure this last thing out. Aside from if I find any bugs, I think once this is done, I can release the scenario or at least public ally make it available for playtest, but this is a critical error, so if anyone can help I appreciate it.

This looks to be your error. In onLoad, you have these lines:
Code:
state = civlua.unserialize(buffer)
-- other stuff
state.Japan2ndFleetDecision = {}
state.USNTaskForce17Decision = {}
state.USNTaskForce16Decision = {}
What the last 3 lines do is replace whatever is stored in the state table at those keys with an empty table. This effectively erases the decision that is made.

What you want is
Code:
state.Japan2ndFleetDecision =state.Japan2ndFleetDecision or {}
state.USNTaskForce17Decision =state.USNTaskForce17Decision or {}
state.USNTaskForce16Decision =state.USNTaskForce16Decision or {}
What this does is say that if state.Japan2ndFleetDecision is not nil or false (i.e., it already exists), keep it. If it is nil (or false), which is to say that it doesn't exist, create an empty table so that it is initialized. That way, all the code that deals with state.Japan2ndFleetDecision can safely assume that the table already exists. The or function works thus: arg1 or arg2 returns arg1 if arg1 is true, otherwise, it returns arg2. This makes logic work as expected, but also allows this kind of initialization trick.

However, it looks like you want state.Japan2ndFleetDecision to be a number, not a table, so you don't need to do any of this. You can just delete the 3 lines (and their corresponding lines near the top of events.lua, which should also have the form I've described when they are needed), and everything should work fine.
 
Thank you! Removing those lines made it work like a charm. Thanks!
 
Top Bottom