Page 41 of 396

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 26, 2015 10:42 pm
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/

Re: Ask a simple question, get a simple answer

Posted: Mon Jan 26, 2015 11:40 pm
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.

Re: Ask a simple question, get a simple answer

Posted: Tue Jan 27, 2015 1:20 am
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.

Re: Ask a simple question, get a simple answer

Posted: Tue Jan 27, 2015 2:03 am
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!

Re: Ask a simple question, get a simple answer

Posted: Tue Jan 27, 2015 2:41 am
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

Re: Ask a simple question, get a simple answer

Posted: Tue Jan 27, 2015 4:32 pm
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

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 30, 2015 12:08 am
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...

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 30, 2015 12:53 am
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

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 30, 2015 3:49 am
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.

Re: Ask a simple question, get a simple answer

Posted: Fri Jan 30, 2015 9:55 pm
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