Page 1 of 1

Defining object ingame

Posted: Thu Nov 06, 2014 12:59 am
by Jouki
Ciao, have someone tried find the way how to define object in game? (in editor script)

Re: Defining object ingame

Posted: Thu Nov 06, 2014 12:56 pm
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.

Re: Defining object ingame

Posted: Thu Nov 06, 2014 1:07 pm
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.

Re: Defining object ingame

Posted: Thu Nov 06, 2014 2:40 pm
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.