Page 1 of 2

cloneObject is nil

Posted: Sun Aug 16, 2015 1:18 am
by Centauri Soldier
Hi all,

Intro
It's been a while since I've been on the forums and I'm back for a little help. I scripted back in Legend of Grimrock I but am just starting in Legend of Grimrock II and having a little trouble.

Background
I've been scripting in lua for about 12 years now and am proficient with lua itself and am also very comfortable with OOP specifically in C#, but OOP none-the-less.

The Problem
So, I'm trying to clone an object using the scripting tutorial's most basic example by placing the following code in the items.lua file in my mod_assets/scripts folder and calling the import function for the items.lua file in my init.lua file.

Code: Select all

cloneObject{
	name = "super_machete",
	baseObject = "machete",
	uiName = "Super Machete",
	attackPower = 12,
	damageType = "shock",
	description = "This machete radiates with strange energy.",
}
For some reason, whenever I load or reload the project i get an error that says "mod_assets/scripts/items.lua: 4 attempt to call 'cloneObject' (a nil value)".

I've been trying to solve this for about 5 hours, reading forum posts, watching tutorials and searching google as well as experimenting on my own. I've even triple checked my game files to be sure I am up-to-date. I'm sure I'm doing something wrong but I just can't figure out what it is. This is maddening :P, any tips or direction would be most appreciated.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 1:45 am
by Sutekh
Use 'defineObject' instead of 'cloneObject'.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 1:47 am
by Centauri Soldier
Well, so far that's working. Thanks :D! What happened to cloneObject? Is it no longer supported?

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 1:51 am
by JohnWordsworth
With defineObject you now pass a "baseObject" parameter if you want to clone an existing item and just overwrite a few components.

If you look at the items in the grimrock 2 asset pack, you will see they do that in the main game to save on duplication :).

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 1:54 am
by Centauri Soldier
I see, so cloneObject was pulled to streamline and optimize the code then.

My old framework seems to be importing now.

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 3:08 am
by Centauri Soldier
Lol, so, I just noticed you can use external scripts in this version of the editor...no need to hack my external scripts into the game.

EDIT:
I can load the scripts but they are not global for other scripts to see for some reason. So my Util script loads fine but the editor can't see any of the functions within it such as Util.GetMonsterCount(). I've named my script entity Util and within the script file is a function called GetMonsterCount.

Even if I add it as a connector, the editor can see the functions but I can't add arguments or use the functions from anywhere else.

Shouldn't this work? Shouldn't other scripts and script entities within the game be able to see that function?

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 3:16 am
by Isaac
The component model changes things a bit. Scripts are in the script component.

Try this: Util.script.GetMonsterCount()

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 3:22 am
by Centauri Soldier
Excellent, thank you very much :D! I'll just have some refactoring to do throughout my code to account for this. Much obliged for all the quick responses :D .

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 5:18 am
by Centauri Soldier
Got another question for you all since the Scripting Reference documentation is currently lacking.

I'm trying to get the mouse position. Now, the SR says to use a GraphicalContext to access this property but I could not find out how to find or create a GraphicalComponent. Any ideas?

Re: cloneObject is nil

Posted: Sun Aug 16, 2015 5:59 am
by Diarmuid
Hey Centauri Soldier! I don't know the answer to this last question, but it's just nice to see old-timers from the early days coming back :) Hope things have been good for you, if you want a quick dive back into modding for LoG2, why not check out the ORRR3 project? John Wordsworth's leading it this time around and there's still some free rooms so you can join the party.