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

cloneObject is nil

Post 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.
User avatar
Sutekh
Posts: 129
Joined: Sun Nov 25, 2012 9:58 am
Location: UK

Re: cloneObject is nil

Post by Sutekh »

Use 'defineObject' instead of 'cloneObject'.
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

Post by Centauri Soldier »

Well, so far that's working. Thanks :D! What happened to cloneObject? Is it no longer supported?
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 »

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 :).
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 see, so cloneObject was pulled to streamline and optimize the code then.

My old framework seems to be importing now.
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

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

Re: cloneObject is nil

Post by Isaac »

The component model changes things a bit. Scripts are in the script component.

Try this: Util.script.GetMonsterCount()
User avatar
Centauri Soldier
Posts: 22
Joined: Sat Dec 29, 2012 10:45 am

Re: cloneObject is nil

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

Re: cloneObject is nil

Post 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?
Last edited by Centauri Soldier on Sun Aug 16, 2015 7:29 am, edited 1 time in total.
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: cloneObject is nil

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