Page 1 of 2
simple help?
Posted: Fri Nov 07, 2014 11:25 am
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

Re: simple help?
Posted: Fri Nov 07, 2014 11:30 am
by JohnWordsworth
In your case, "s" is just a simple string. You can only use the
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
Re: simple help?
Posted: Fri Nov 07, 2014 11:31 am
by Blichew
:EDIT: haha, John got to it first
creates a string variable. You probably have to make an entity of it:
Then, inside IF clause you want to check .id of that entity, not the entity itself,so go with that:
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
Re: simple help?
Posted: Fri Nov 07, 2014 11:34 am
by Jouki
haha

I've just figured out how todo that too, maybe I should try something before I ask

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
Re: simple help?
Posted: Fri Nov 07, 2014 11:36 am
by Blichew
Jouki wrote:haha

I've just figured out how todo that too, maybe I should try something before I ask

have already another problem, ~= is not working how I though it should works.
Elaborate please, I'm extremely bored at work

Re: simple help?
Posted: Fri Nov 07, 2014 11:41 am
by Jouki
Blichew wrote:Jouki wrote:haha

I've just figured out how todo that too, maybe I should try something before I ask

have already another problem, ~= is not working how I though it should works.
Elaborate please, I'm extremely bored at work


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
Re: simple help?
Posted: Sat Nov 08, 2014 12:11 am
by Jouki
guys can someone write me the syntax of setting the lever state?

I've got oly errors or crashes
I think I tried everything with or w/o component but nothing seems to work

I'm sure I'm missing something
Re: simple help?
Posted: Sat Nov 08, 2014 12:29 am
by jxjxjf
Pass the state as a string. Either "activated" or "deactivated" like:
Code: Select all
lever.lever:setState("deactivated")
Re: simple help?
Posted: Sat Nov 08, 2014 12:48 am
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

Re: simple help?
Posted: Sat Nov 08, 2014 1:44 am
by NutJob
isActivated(), not isActive()