Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.Magazine is nil in Create() #88

Open
MyNameIsTrez opened this issue Feb 18, 2024 · 3 comments
Open

self.Magazine is nil in Create() #88

MyNameIsTrez opened this issue Feb 18, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@MyNameIsTrez
Copy link
Contributor

MyNameIsTrez commented Feb 18, 2024

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 MyNameIsTrez added the bug Something isn't working label Feb 18, 2024
@Causeless
Copy link
Contributor

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
Copy link
Contributor

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

@MyNameIsTrez
Copy link
Contributor Author

MyNameIsTrez commented Feb 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants