Page 2 of 2

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 7:18 am
by Centauri Soldier
Hey, thanks for the kind welcome back :). I'd love to join the project but I'm currently working on a dev team and going to school. I will certainly check it out though just to try to get some tips, thanks.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 11:09 am
by JohnWordsworth
If you do happen have a week of free time within the next few months and an idea pops into your head - then you're more than welcome to the join the ORRR3 later and contribute a room. :)

With regards to getting the mouse position, you get a GraphicsContext as a parameter to the onDrawGui etc party hooks. I don't think there is any other way to get the GraphicsContext object so if you really need the mouse position in other scripts, my advice would be to make a very simple onDrawGui hook for the party which stores the mouse position in another script entity somewhere.

Just out of curiosity - why do you need the mouse position outside of a GUI context?

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 6:20 pm
by Centauri Soldier
I may do that, John, thanks for the invite. Do you have a link handy?

Thanks for the tip on the GraphicsContext, I'll give that a shot and let you know how it turns out.

I needed the mouse position to use at the start of my Mersenne Twister seed calculation. Adding a little user input as "randomness" will greatly improve it. Although, as it stands, I think I have a very good PRNG seed so far. I haven't got any duplicates with this function.

Code: Select all

        --create the pre-seed for the Mersenne Twister
	local nMersennePreSeed = math.ceil(Time.systemTime() + Time.deltaTime() * 1000000);
       --returns either 1 or -1
	local nMPS_Alternator = Util.script.Math_GetAlternator();
	local nMPS_Addative = Time.systemTime() + (Time.deltaTime() * nMersennePreSeed * nMPS_Alternator);
	nMersennePreSeed = math.ceil(nMersennePreSeed + nMPS_Addative);	
	--create the twister
	MersenneTwister.create(nMersennePreSeed);
	
	--pre math.randomseed value
	math.randomseed(nMersennePreSeed);	
	--create the math.randomseed value
	local nMRSMin = math.ceil(Time.deltaTime() * 882937);
	local nMRSMax = math.ceil(Time.systemTime() * 8829373);
	local nMathSeed = Util.script.Math_Rand(1, Util.script.Math_Rand(nMRSMin, nMRSMax));
	--seed the math.random lua function
	math.randomseed(nMathSeed);
		
	--create the Mersenne Twister seed value
	local nMSMin = Util.script.Math_Rand(1, 78364);
	local nMSMax = math.random(123235453, Util.script.Math_Rand(math.ceil(Time.deltaTime()) * 45536, 987897843533));
	local nMersenneSeed = Util.script.Math_Rand(nMSMin, nMSMax);
	--this is the number for the maximum numerator and denominator used in multiplying the final Mersenne Twister seed value
	local nVarianceRange = Util.script.Math_Rand(1, 12);
	local nNumerator = Util.script.Math_Rand(1, nVarianceRange);
	local nDenominator = math.random(1, nVarianceRange);
	nMersenneSeed = math.ceil(nMersenneSeed * ( nNumerator / nDenominator ));
	--create the Mersenne Twister
	tUtil.Twister = MersenneTwister.create(nMersenneSeed);
This is general utility function but what I'm currently applying to is my random monster generator which works wonderfully now :). It needs a little updating to reflect the changes in monster names, types and varaible level types in LoG2 but other than that it's coming along. I really appreciate everyone who's helped me over the starting hurdles.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 6:44 pm
by Isaac
One way to get a different seed every time is to use the current duration of play_time; though it's not random, it will never duplicate.

MersenneTwister.create(GameMode.getStatistic("play_time"))

** I've not often used (or tested) the MersenneTwister object; if there is a practical reason not to use the above, then it's something I'd like to know about.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 7:11 pm
by Centauri Soldier
I think that's being implemented when I'm using Time.deltaTime().

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 7:57 pm
by minmay
Time.deltaTime() is the time elapsed since the previous update. So if the game is running at 60 fps it will be 16.67. You probably wanted Time.currentTime().

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 8:17 pm
by Centauri Soldier
Oh, right, I'll change that, thanks all.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 9:19 pm
by JohnWordsworth
Sure thing - you can read more about the ORRR3 here.

With regards to the Mersenne Twister - I would imagine using a combination of Time.systemTime and Time.currentTime would be good enough.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 11:56 pm
by minmay
Mersenne Twister is not remotely close to cryptographically secure in the first place, no matter how good your seed is.

Re: cloneObject is nil

Posted: Mon Aug 17, 2015 12:48 am
by Centauri Soldier
No this isn't for any cryptographic application. And, yes, cryptography is its own beast and a completely different topic. I've been studying that subject for over a year now and feel like I'm just scratching the surface.

I was merely trying to get a very good sense of randomness when my level spawns the monsters. The spawner script randomizes many things including total monsters, monster type, monster level and location on the map.