Page 1 of 2

Help needed with really simple scripts

Posted: Fri Oct 26, 2012 11:10 pm
by Merethif
The first question is probably very silly but please mind that I'm at the very beginning of script using, not to even mention script making.
So I've been trying to use one of the scripts from repository but I fail every time and I really don't know what am I doing wrong.
Generally I'm looking for a teleporter activated with an item being in inventory (like the one with Fighter's Challenge and Sword of Nex).
I've found several suitable scripts in repository (viewtopic.php?p=31831#p31831), but for example when I'm using first one I get error: 'then' expected near '=' X after the line: if item.name = "blueberry_pie" then. With the script from next post I got: attempt to call method 'getItem' (a nil value) X after line: local itemObj = champion:getItem(i).

The second question is about stacks of items in container in alcove.
For example if I got:
SpoilerShow

Code: Select all

local merethifsack = spawn("sack")
   merethifsack:addItem(spawn("sling"))
   merethifsack:addItem(spawn("rock"))
   merethifsack:addItem(spawn("rock"))
   merethifsack:addItem(spawn("rock"))
merethifsackAlcove:addItem(merethifsack)
Is there an option to spawn all those three rocks in single container slot?

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 12:30 am
by Komag
you can add the stack count right on the same line, before the end )

error "then", you need == not =

(typing on phone)

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 2:25 pm
by crisman
you should try with this:

Code: Select all

local itemObj = champion:getItem(i)
if itemObj ~= nil then
*do whatever you want*
end
for the rocks there is a setStack(n) script
let me know!

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 2:57 pm
by Merethif
Thanks for help. Sadly, due to my lack of knowledge I'm still unable to solve both issues.

I'm not sure how to add the stack thing.
sack:addItem(spawn("rock")setStack(2)) doesn't work
merethifsack:addItem(spawn("rock")setStackSize(2)) neither.

As for the other script, adding == instead of = seems to be fine since there's no more error message, but still it doesn't work (nothing happens when I step on plate that activates script with item in backpack). Also I must admit I'm not sure where should I put those lines you provided crisman. I suppose I may need a step by step guide for dummies (with helpful comments and such).

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 3:38 pm
by crisman
my bad, the correct script is getStackSize(n)

The correct script is something like this:
SpoilerShow

Code: Select all

local sack1 = spawn("sack")
sack1:addItem(spawn("rock"):setStackSize(3))
alcove:addItem(sack1)

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 3:58 pm
by Merethif
crisman wrote:my bad, the correct script is getStackSize(n)

The correct script is something like this:
SpoilerShow

Code: Select all

local sack1 = spawn("sack")
sack1:addItem(spawn("rock"):setStackSize(3))
alcove:addItem(sack1)
Ok, so I was experimenting with setStackSize(n), putting different combination with it in different places, when all I've needed was a colon! There's nothing more enlightening then a good example.
Thanks a lot! :-D

Probably I'm missing something as obvious as colon in the other one as well.

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 4:59 pm
by crisman
Columns are just a way to tidy up the code a bit, if you want you can write it in a single row :D
(this is untested, some parenthesis may be missing or in wrong place)
alcove:addItem(spawn("sack"):(addItem(spawn("rock"):setStackSize(3))))

For the other code: I'd like to see, if possible, what you wish to do with champion:getItem(i)
--maybe it's just because you need party:getChampion(a):getItem(i)?

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 5:19 pm
by Komag
here is another example:

Code: Select all

local alchSack = spawn("sack")
alchSack:addItem(spawn("scroll"):setScrollText("Potion of Healing\n1 flask\n1 tar bead\n\nAntivenom\n1 flask\n1 cave nettle"))
alchSack:addItem(spawn("mortar"))
alchSack:addItem(spawn("flask"))
alchSack:addItem(spawn("flask"))
alchSack:addItem(spawn("tar_bead"):setStackSize(2))
alchSack:addItem(spawn("cave_nettle"))
alchAlcove:addItem(alchSack)

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 9:06 pm
by Merethif
crisman wrote:For the other code: I'd like to see, if possible, what you wish to do with champion:getItem(i)
--maybe it's just because you need party:getChampion(a):getItem(i)?
I've been mostly coping scripts from repository and paste them into single script_entity (the entity is activated by a hidden plate with deactivated teleporter, named entrance_teleporter on the same tile). For example something like this :
SpoilerShow

Code: Select all

    function checkForItemParty(item)
       local i = 1
       repeat
          if checkForItem(party:getChampion(i), item)
             then return true
          end
          i = i + 1
       until i == 5
       return false
    end

    function checkForItem(champion, item)
       local i = 1
       repeat
          local itemObj = champion:getItem(i)
          if itemObj ~= nil then
             if itemObj.name == item
                then return true
             end
          end
          i = i+1
          until i == 32
       return false
    end

    if checkForItemParty("entrance_scroll")
      then
      entrance_teleporter:activate()
      else
     entrance_teleporter:deactivate()
      end
end
    end
And thanks Komag for another script - the more sacks in alcoves, the better :-D

Re: Help needed with really simple scripts

Posted: Sat Oct 27, 2012 10:44 pm
by crisman
The script you gave me it's working fine, just had to tweak a little bit - delete last end and put function check() between last if and the end above it. Anyway, I'd like to give you a much simpler code for that:
SpoilerShow

Code: Select all

function check()
for i = 1, 4 do
	for j = 1, 31 do
	local itemObj = party:getChampion(i):getItem(j)
		if itemObj ~= nil then
			if itemObj.name == "rock" then
				teleporter_1:activate()
			end
		end
	end
end
end
It does not deactivate the teleporter though, it will only need a couple more strings.