Ask a simple question, get a simple answer

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
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:Well Isaac's post is just completely wrong, actually. The error has nothing to do with a concatenation that you're performing.
It is a funny thing that as I read it (the first time), I understood it to mean that the error happened [immediately] upon the death of the warden; clearly I missed the last bit about saving the game at the crystal. Image

Yes... variables in script functions not set to local cause errors upon attempting to save the game.
Note: @TheLastOrder... Not all variables in the scripts are required to be local; some cannot be. To get a good understanding of it, AH has a dedicated page about this:
http://www.grimrock.net/modding/save-ga ... variables/
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Isaac wrote:Yes... variables in script functions not set to local cause errors upon attempting to save the game.
If a variable isn't set to local, then it isn't in a function, period. Even if you declare it inside a function, it becomes a field of the ScriptComponent, not a variable that belongs to the function block.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:
Isaac wrote:Yes... variables in script functions not set to local cause errors upon attempting to save the game.
If a variable isn't set to local, then it isn't in a function, period. Even if you declare it inside a function, it becomes a field of the ScriptComponent, not a variable that belongs to the function block.
True or False: Adding the local keyword indiscriminately to script variables can create upvalues.
(If the variable is outside of a function, but used inside of one.)

It won't even preview in the editor; though it will export to dat, and crash the game when loaded.

I mentioned it on the odd chance that TheLastOrder meant to add "local" to ~everything.
User avatar
TheLastOrder
Posts: 104
Joined: Wed Oct 17, 2012 1:56 am

Re: Ask a simple question, get a simple answer

Post by TheLastOrder »

So I think I have understood where´s the problem:

Code: Select all

Bertolucci.monster:addConnector("onDie", "tomebertolucci", "tomebertolucci")
I added, through script, a connector on a monster that respawns and, once he has died, he activates another script.... where I spawn an OBJECT that doesn´t exist...
Is this object the one causing this trouble, if I understood correctly :?:

This is that script I´m talking about:

Code: Select all

function tomebertolucci()
     b = party.party
     spawn("tome_water",b.level,b.x,b.y,b.facing,b.elevation)
end
So probably this is the solution.... :?:

Code: Select all

function tomebertolucci()
     b = party.party
     local item = spawn("tome_water",b.level,b.x,b.y,b.facing,b.elevation)
end
:mrgreen: Thank you again guys!
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: Ask a simple question, get a simple answer

Post by Batty »

TheLastOrder wrote:So probably this is the solution.... :?:
ummm...no, the problem is

Code: Select all

b = party.party
so, for reasons previously illustrated you could do:

Code: Select all

local b = party.party
but I would just do:

Code: Select all

function tomebertolucci()
     spawn("tome_water", party.level, party.x, party.y, party.facing, party.elevation, nil)
end
User avatar
TheLastOrder
Posts: 104
Joined: Wed Oct 17, 2012 1:56 am

Re: Ask a simple question, get a simple answer

Post by TheLastOrder »

Batty, you´re absolutely right :oops:

The variable in the script that the game can´t storage when saving is b.

Thank you very much! :D
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

I forgot how to call all entities of an item in a script. I mean all torches in the game: torch_1, torch_2, torch_3 ...
What was it like? "torch_i" is wrong.. ??

What I want to do is destroying all of them...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Well to help myself, I found this:

viewtopic.php?f=22&t=7951&start=140#p83415
NutJob wrote:

Code: Select all

local obj;
for i=1,10 do
    obj = findEntity("teleporter_" .. i)
    -- do stuff to obj
end

But I can not figure out what "do stuff with obj" means. How to use it.

obj:destroy() doesn't work
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Ask a simple question, get a simple answer

Post by GoldenShadowGS »

THOM wrote:Well to help myself, I found this:

viewtopic.php?f=22&t=7951&start=140#p83415
NutJob wrote:

Code: Select all

local obj;
for i=1,10 do
    obj = findEntity("teleporter_" .. i)
    -- do stuff to obj
end

But I can not figure out what "do stuff with obj" means. How to use it.

obj:destroy() doesn't work

Paste your code so we can debug it.
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

GoldenShadowGS wrote: Paste your code so we can debug it.
Well then. The situation is a bit tangled.

I have an alcove where you have to put an air-essence on to unlock a key. For certain reasons it is possible, that players choose another alcove to put the essence on - but then the essence is locked in that alcove and the player can't get it back (I have put a forcefield over this alcove but you can put items through it if it's on a wall (!) - not if it's alone in the room! But you can't take items back when they are in the forcefield.)

To avoid a dead end I thought it could be a good idea to avoid putting the air essence into the alcove. I have tried to script something: when you put the essence trough the forcefield in the wrong alcove, the essence will be destroyed and recreated in the mouse. But therefore every time another unique item id is created, I cannot destroy the essence in my way. I need a trick to destroy all essenceses regardless which id-number they have.

This is, what I have tried:

Code: Select all

function surfaceContains(surface, item)
   for _,i in surface:contents() do
      	if i.go.name == item then return true 
		end
   end
end


function keepEssence()
	if	surfaceContains(castle_alcove_key.surface, "essence_air")
		then
			timer_setMouseEssence.timer:enable() -- timer just delays recreation
			--print("timer")
	end	
end


function setMouse() -- called by timer
	for i, ent in castle_alcove_key.surface:contents() do
          		local obj;
				for x=1,100 do
    				obj = findEntity("
					essence_air_"..x..":destroy() --this line seems to be wrong! with 'essence_air_1' it works - but just once...
				end
 				--print("destroy")
       		end
	setMouseItem(spawn("essence_air",nil,nil,nil,nil,nil).item)
	--print("create")
end
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Post Reply