cloneObject is nil

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

Post 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.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: cloneObject is nil

Post 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?
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

Post 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.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: cloneObject is nil

Post 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.
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

Post by Centauri Soldier »

I think that's being implemented when I'm using Time.deltaTime().
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: cloneObject is nil

Post 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().
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

Post by Centauri Soldier »

Oh, right, I'll change that, thanks all.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: cloneObject is nil

Post 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.
Last edited by JohnWordsworth on Mon Aug 17, 2015 1:12 pm, edited 1 time in total.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: cloneObject is nil

Post by minmay »

Mersenne Twister is not remotely close to cryptographically secure in the first place, no matter how good your seed is.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

Post 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.
Post Reply