Defining object ingame

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!
Post Reply
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Defining object ingame

Post by Jouki »

Ciao, have someone tried find the way how to define object in game? (in editor script)
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

Re: Defining object ingame

Post by antti »

You can't define new objects while in editor but you can modify existing (spawned) objects considerably by modifying its components or creating new components. This can be suitable for some one-off objects but in general you're better off if you just do them the traditional way with the init scripts.
Steven Seagal of gaming industry
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: Defining object ingame

Post by Blichew »

On a side-note: defining custom stuff in-game and reverse-engineering definitions:

is there a way to let's say dump item definition (every component and it's parameters) into array (like item is defined with defineObject) so it can be further printed with

Code: Select all

function tprint (tbl, indent)
	if not indent then indent = 0
	end
	for k, v in pairs(tbl) do
		formatting = string.rep(" ", indent) .. k .. ": "
		if type(v) == "table" then
			print(formatting)
			tprint(v, indent+1)
		else
			print(formatting .. v)
		end
	end
end
I've tried that with console:
sb = spawn("short_bow")
script_entity_1.script.tprint(sb) but nothing happens.
Maybe i should try doing it with GameObject:getComponent(name) to save every component into array ?

:EDIT: I think something is wrong with my tprint function, because:

Image

value sb clearly is a table.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Defining object ingame

Post by MrChoke »

I have noticed this too. pairs() and ipairs() doesn't return anything on Grimrock objects. They work fine on tables you make yourself. I am sure this was done on purpose for whatever reason (probably doing a metamethod command on the tables so they cannot be iterated).

We can only go off of the documentation and trial and error to figure these out.
Post Reply