Cortex-Command-Community-Project icon indicating copy to clipboard operation
Cortex-Command-Community-Project copied to clipboard

self.Magazine is nil in Create()

Open MyNameIsTrez opened this issue 1 year ago • 3 comments

Describe the bug self.Magazine can seemingly randomly be nil in Create()

Pawnis' recent Browncoat script even points it out with a comment, in Data/Browncoats.rte/Devices/Weapons/Extinction/Extinction.lua:

self.maxAmmoCount = self.Magazine and self.Magazine.Capacity or 5; -- loading a game might mess this up, so... fall-back

In the mod I found the issue, the error originates from here:

function Create(self)
	self.ammoCounter = 100
	self.recoil = 0

	self.ff = false

	print(self.Magazine)
	self.f0 = ToMagazine(self.Magazine).RoundCount

	self.f1 = ToMagazine(self.Magazine).RoundCount
	self.firetimer = Timer()
end

I added the print(self.Magazine), and it shows that self.Magazine is nil a portion of the time it gets printed here.

Where the single ini file where it's used looks roughly like this:

AddAmmo = Magazine
	PresetName = Magazine ChainChoppa

AddDevice = HDFirearm
	PresetName = Chain Choppa
	ScriptPath = orks.rte/Weapons/ChainChoppa/ChainChoppa.lua
	Magazine = Magazine
		CopyOf = Magazine ChainChoppa

To Reproduce I haven't taken the time to make a Minimal Reproducible Example yet, but this should show the error after a minute or two of running:

  1. Download orks.rte.zip
  2. Download Benchmark.rte.zip
  3. Use this in your Settings.ini to instantly have the issue printed when the game boots:
	LaunchIntoActivity = 1
	DefaultActivityType = GAScripted
	DefaultActivityName = Combat Benchmark
	DefaultSceneName = Benchmark

MyNameIsTrez avatar Feb 18 '24 00:02 MyNameIsTrez

Worth noting that Pawnis' case is due to save-loading, where having the Magazine be nil is indeed a valid case if the game is saved mid-reload... (and having mods be compatible with save-loading ought to account for this!). But I'll look at why this is happening without a save-load cycle

Causeless avatar Feb 18 '24 00:02 Causeless

If this is happening without save/load, is it not possible that the script is being added to a gun perhaps mid-reload?

Causeless avatar Feb 18 '24 17:02 Causeless

So I can confirm that this also happened in Pre 5.0.

If this is happening without save/load, is it not possible that the script is being added to a gun perhaps mid-reload?

It might, but it's hard to know for sure. I know for a fact that looking for chainchoppa.lua in the project with Ctrl+Shift+F only results in it being mentioned in its ChainChoppa.ini

MyNameIsTrez avatar Feb 18 '24 22:02 MyNameIsTrez