simple help?

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
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

simple help?

Post by Jouki »

I'm not pro with that but I guess the problem is variable s is only string not the object. I hope it's clear what is meant by that

Code: Select all

function lever1()
	for i=1,15,1 do
	s = "spike_" .. i
		if s ~= "spike_2" or s ~= "spike_3" or s ~= "spike_6" then
			s.controller:activate()
			print(s)
		end
	end
	timer_18.timer:enable()
end
Image
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: simple help?

Post by JohnWordsworth »

In your case, "s" is just a simple string. You can only use the

Code: Select all

entityName.component:method() 
trick where "entityName" is not a variable defined within your script and is an entity defined in the game world. In your code, "s" is a variable that you have defined and so typing "s.controller" simply tries to look for the property "controller" on the local object "s" (which is just a string).

What you want to do is something like this...

Code: Select all

local entityName = "spike_" .. i

if entityName ~= "spike_2" or entityName ~= "spike_3" or entityName ~= "spike_6" then
  local entity = findEntity(entityName) 
  entity.controller:activate() 
  print(entity.id)
end
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: simple help?

Post by Blichew »

:EDIT: haha, John got to it first ;)

Code: Select all

s= "spike_"..i
creates a string variable. You probably have to make an entity of it:

Code: Select all

s = findEntity("spike_"..i)
Then, inside IF clause you want to check .id of that entity, not the entity itself,so go with that:

Code: Select all

if s.id ~= "spike_2"

Code: Select all

function lever1()
   for i = 1,15,1 do
   s = findEntity("spike_"..i)
      if s.id ~= "spike_2" or s ~= "spike_3" or s ~= "spike_6" then
         s.controller:activate()
         print(s.id)
      end
   end
   timer_18.timer:enable()
end
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: simple help?

Post by Jouki »

haha :lol: I've just figured out how todo that too, maybe I should try something before I ask :D have already another problem, ~= is not working how I though it should works.

Code: Select all

function lever1()
	for i=1,15,1 do
	s = findEntity("spike_" .. i)
		if not s == spike_2 or not s == spike_3 or not s == spike_6 then
			s.controller:activate()
		end
	end
	timer_18.timer:enable()
end
edit: I'm gonna try your solutions I believe there's a problem with "s.id" gimme a sec
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: simple help?

Post by Blichew »

Jouki wrote:haha :lol: I've just figured out how todo that too, maybe I should try something before I ask :D have already another problem, ~= is not working how I though it should works.
Elaborate please, I'm extremely bored at work :P
Last edited by Blichew on Sat Nov 08, 2014 1:31 am, edited 1 time in total.
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: simple help?

Post by Jouki »

Blichew wrote:
Jouki wrote:haha :lol: I've just figured out how todo that too, maybe I should try something before I ask :D have already another problem, ~= is not working how I though it should works.

Elaborate please, I'm extremely bored at work :P
:lol: ok so entities working but condition not, I think I tried all combinations with "", without, with ~=, with not, but nothing seems to work

edit: hmmm, the problem is in "or"

edit2: jeeez I'm idiot xD I forgot write .id to the rest of spikes and idk how but "and" condition works properly

Code: Select all

function lever1()
   for i = 1,15,1 do
   s = findEntity("spike_" .. i)
      if s.id ~= "spike_2" and s.id ~= "spike_3" and s.id ~= "spike_6" then
         s.controller:activate()
         --print(s.id)
      end
   end
   timer_18.timer:enable()
end
edit3: oh now I get it, it's negative of condition so I have to negate the clauses
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: simple help?

Post by Jouki »

guys can someone write me the syntax of setting the lever state? :P I've got oly errors or crashes :mrgreen:

Code: Select all

lever:setState(deactivate)
I think I tried everything with or w/o component but nothing seems to work :( I'm sure I'm missing something
User avatar
jxjxjf
Posts: 33
Joined: Fri Oct 24, 2014 6:26 am

Re: simple help?

Post by jxjxjf »

Pass the state as a string. Either "activated" or "deactivated" like:

Code: Select all

lever.lever:setState("deactivated")
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: simple help?

Post by Jouki »

jxjxjf wrote:Pass the state as a string. Either "activated" or "deactivated" like:

Code: Select all

lever.lever:setState("deactivated")
Thanks I had to figure out like this:

Code: Select all

if lever.lever:isActive() == true then lever.lever:toggle() end
:lol:
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: simple help?

Post by NutJob »

isActivated(), not isActive()
Post Reply