paulofmandown / rotLove

Roguelike Toolkit in Love. A Love2D/lua port of rot.js
http://paulofmandown.github.io/rotLove/
Other
261 stars 26 forks source link

Immediate use of newly initialized RNGs (any) crashes #11

Closed globalcitizen closed 7 years ago

globalcitizen commented 8 years ago

When initialized and used as follows...

-- first, one of ...
randomsource = ROT.RNG.LCG:new()
randomsource = ROT.RNG.MWC:new()
randomsource = ROT.RNG.MWC:new()
-- then
randomsource:random(1,100)

... ROT.RNG.<whatever> causes something like:

Error: rotLove.lua:450: attempt to perform arithmetic on field 'x' (a nil value)

That line is, for example:

local t = self.a * self.x + self.c

The a and c are supplied, eg...

function ROT.RNG.MWC:random(a, b)

So the culprit seems to be self.x, which seems to be some kind of mystic state table thing inherited from RNG? Perhaps I missed some initialization. Anyway, defaults should work... fixing this in rotLove itself is beyond me.

globalcitizen commented 8 years ago

Looking in the demos it seems I need to first manually call randomsource:randomseed() ... this should be automatic.

paulofmandown commented 7 years ago

This was addressed by airstruck with 5d939011ff93dd796f6cfa4db73de686a0820c4c