Page 1 of 2

Scripting cheat sheet

Posted: Sun Dec 02, 2012 4:13 pm
by JKos
Hi,

I made a cheat sheet for LoG scripting:
https://sites.google.com/site/jkosgrimr ... heat-sheet

I think it could be useful to someone else too.

Re: Scripting cheat sheet

Posted: Sun Dec 02, 2012 4:35 pm
by msyblade
This is super useful JKos. I'm constantly using references for specific syntax or commands. This is perfect!

Re: Scripting cheat sheet

Posted: Sun Dec 02, 2012 6:03 pm
by Diarmuid
Very useful indeed! Thanks, this will save us a lot of time.

Re: Scripting cheat sheet

Posted: Sun Dec 02, 2012 6:40 pm
by Kuningas
Fantastic! Saves a lot of time for me.

Thank you.

Re: Scripting cheat sheet

Posted: Sun Dec 02, 2012 10:05 pm
by Komag
yes! very concise and complete, love it! :D

Re: Scripting cheat sheet

Posted: Sun Dec 02, 2012 10:34 pm
by Nickydude
Thanks/ :)

Re: Scripting cheat sheet

Posted: Mon Dec 03, 2012 3:32 am
by Grimwold
An excellent resource. Thanks for sharing!

Re: Scripting cheat sheet

Posted: Mon Dec 03, 2012 9:31 am
by Xanathar
Fantastic! Will definitely use it!

Re: Scripting cheat sheet

Posted: Mon Dec 03, 2012 9:39 pm
by JKos
Thanks for the great response. I got an idea for another cheat sheet: It would be nice to have a lua syntax/tips/warnings cheat sheet for LoG specific lua scripting because like we all know the lua support is a bit limited and there is also some restrictions. But because it's much more work than just copy pasting functions from documentation I was thinking that maybe we could make it together, just write your (short) lua tips/tricks here and I will make a another cheat sheet of them.

I can start of course so you get the idea.

STRINGS

Code: Select all

"a".."b" == "ab"
"a"..0 == "a0"

Code: Select all

multiLineString = [[
Hello
Grimrock!
]]
multiLineString = "Hello\nGrimrock!"

TABLES

Code: Select all

table1 = {'a','b','c'}
table1[1] == "a"
table2 = {key1='value1'}
table2.key1 == 'value1'
SCRIPT ENTITIES

Code: Select all

property = "a"
function getProperty()
	return property
end
function setProperty(value)
	property = value
end

entity_id.getProperty() == "a"
entity_id.setProperty('c') (ok)

entity_id:getProperty() == "c"
entity_id:setProperty('c') (error)

OBJECT ORIENTED

Code: Select all

local obj = {}
obj.property = "a"
obj.method = function(self) 
		return self.property 
	end
obj:method() == "a"
obj:method() == obj.method(obj)
obj.method() (error)

Code: Select all

-- magic self 
local obj2 = {}
obj2.property = 'b'
function obj2:method()
	return self.property
end
obj:method() == 'b'
obj.method() (error)
WARNINGS (works in editor but not in the game)

Storing entities to "global" variables

Code: Select all

variable = snail_1 (serialization error on save game)
variable = snail_1.id (ok)
local variable = snail_1 (ok)
Undefined "global" variables

Code: Select all

function breakTheGame()
	undefinedGlobal = 'crash'
end
Upvalues

Code: Select all

myMethods = {}
function breakTheGame()
	local upvalue = "causes serialization error"
	myMethods.useExternalLocalVariable = function() 
		print(upvalue) 
	end
end
breakTheGame()

Re: Scripting cheat sheet

Posted: Mon Dec 03, 2012 10:39 pm
by Komag
Holy heck this is extremely valuable. I'm only just starting to get a grasp on most of this stuff, so thank you!