Scripts / Detect which switch sent the activate to visual linked item

Author
Message
TrezSoft
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 9th Oct 2022 17:47
If I have two switches , both linked to another entity using visual logic (toggle) and then in the new entity lua script detect which switch sent the activate ?.

Basically i would like to name the two entities in the dynamic lua Switch A , Switch B to match the switch entity names and then act on them in a new entity based on matched names. Switch A - activated , Switch B - not activated , output not activated, Switch A - activated , Switch B activated - output activated. ( Normal logic gates ).

Thanks

Stuart



EyeFly
2
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 10th Oct 2022 02:54 Edited at: 10th Oct 2022 06:29
You could make 2 new copies of the switch script. Name one "switch a" and the other "switch b". Then add a global value to "switch a" named "g_switch_a" and set it to "g_switch_a = 0" to start with. Then have the switch set it to "g_switch_a = 1" when the switch gets activated. Do the same for "switch b". Then in your other script, use those 2 global values to do something. Like "if g_switch_a == 1 and g_switch_b == 1 then". That should work for you.
Keep Making Stuff You Enjoy.
TrezSoft
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 10th Oct 2022 18:24
Thanks EyeFly made me rethink what how i needed to make it work , this is the current base code requires you to know the entity Id's of the inputs for the gates ( which could be a switch holding this behavior) at the moment i have only implement AND and OR logic gates just to prove concept. So far looks like i can chain a bunch together with additional switches to trigger one or more outputs. Looking to create more complex puzzle switch logic. I have include the code below and i have one question, I needed to tell lua that the entity number properties are numbers else no joy, is this normal ?

local gatea = tonumber(g_logicgate[e].entityida)
local gateb = tonumber(g_logicgate[e].entityidb)

I've attached the script to give the above some context.

Thanks again Stuart
TrezSoft
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 10th Oct 2022 22:54
Seems the file did not attach !, attempt #2
EyeFly
2
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 11th Oct 2022 01:35
Im not sure if that's normal. I'm still a noob when it comes to scripting. But I hope you get it figured out!
Keep Making Stuff You Enjoy.
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 11th Oct 2022 12:57
@ TrezSoft
I'm no so sure if I've got your point, maybe a video might help, anyway, if you take a look at the switch.lua file you will find the following:

if g_Entity[e]['activated'] == 101 then -- switch off
if g_Entity[e]['activated'] == 201 then -- switch on

so, if switch A id = 1 and switch B id = 2, then it should look like this:

if g_Entity[1]['activated'] == 201 and g_Entity[2]['activated'] == 201 then -- both are activated.
-- open your door here, or whatever you want to do.
end

if you do so, then you won't need the global var anymore.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
TrezSoft
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 11th Oct 2022 15:03
@3com

I was attempting to be a bit more dynamic so that different logic gates could be chained together, the behavior below (looks like! it works) for AND, OR, NOT. I see you have used 101 and 201, I don't fully understand the statuses so at the moment they are ['activated'] as 0 or 1.



As it stands it allows you to create more complex switch configurations to activate something, like a light or the Aztec false wall(door)
output is minimal version of what the switch does atm. You can turn on some debug prompt info, after you get a few levels into logic is easy to get lost .

3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 11th Oct 2022 21:03
@ TrezSoft
I've got your point now.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM

Login to post a reply

Server time is: 2024-04-27 00:31:35
Your offset time is: 2024-04-27 00:31:35