Skip to content

self.Magazine is nil in Create() #88

Open

Description

@MyNameIsTrez

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

Activity

  1. Causeless commented on Feb 18, 2024

    @Causeless
    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

  2. Causeless commented on Feb 18, 2024

    @Causeless
    Contributor

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

  3. MyNameIsTrez commented on Feb 18, 2024

    @MyNameIsTrez
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions