Timba Posted October 30, 2019 Share Posted October 30, 2019 Hallo in die Runde, ich habe gerade ausprobiert, ob ich das Ereignis "Variable wird gesetzt" als Auslöser nutzen kann, wenn ich einer Tabelle ein Element hinzufüge. Das Programm hat das geflissentlich ignoriert. Kann ich davon ausgehen, dass "Variable wird gesetzt" bei Tabellen/Listen nicht unterstützt wird? Oder habe ich irgendwas falsch gemacht? Gruß Timba aus dem sonnigen Ostwestfalen Link to comment Share on other sites More sharing options...
EricD Posted October 31, 2019 Share Posted October 31, 2019 Hello Timba Problem: You want to use the "set variable" event as a trigger when you add an item to a table. Suggested solution 1: Each time you add an item to a table you should also change a "dummy" object variable e.g. Your table is called "ThisTable" Your "dummy" is the Trigger button "Trigger1" (but it could be ANY entity in your layout) Stage1: Create a "Switch is toggled" event for "Trigger1" containing: if ThisTable == nil then ThisTable = {} end table.insert(ThisTable, math.random() ) $("Trigger1").variables["ThisTable"] = ThisTable Stage2: Create an "Object variable is changed" event for $("Trigger1").variables['ThisTable'] containing: for k = 1, #ThisTable do print(ThisTable[k]) end Suggested solution 2: Why not get rid of "ThisTable" and always use $("YourEntity").variables['ThisTable"] instead? (Only do this when you need to detect when an item is added to the table) Hope this helps! Detect table insert.mbp Eric Link to comment Share on other sites More sharing options...
Timba Posted October 31, 2019 Author Share Posted October 31, 2019 Hi Eric, thanks for the suggestion. However, it isn't needed anymore. I had several options and using a table.insert as trigger was just one of them. I only posted the question because I thought it is a little weird since tables are in the category of variables and adding data to a table is some kind of "set variable", but it didn't work. Again, thanks for trying to help. Kind regards Timba Link to comment Share on other sites More sharing options...
Goetz Posted October 31, 2019 Share Posted October 31, 2019 vor 2 Stunden schrieb Eric Danvers: Suggested solution 1: Each time you add an item to a table you should also change a "dummy" object variable Why use a back door when you can access the event directly? if ThisTable == nil then ThisTable = {} end table.insert( ThisTable, math.random() ) -- add to a table $("table has changed"):invoke(optional_arguments) -- call the related user event Link to comment Share on other sites More sharing options...
EricD Posted October 31, 2019 Share Posted October 31, 2019 The solution by Goetz is better than mine. Normally, I don't like "work-arounds" but this was all I could think of. I agree that it's better to use $("table has changed"). I'm still learning and am happy to be doing so! Does anyone know how to detect a change in Locomotive speed? i.e. if you change the targetSpeed using the Locomotive control window, how can you detect this change in the Event Manager? Link to comment Share on other sites More sharing options...
Goetz Posted October 31, 2019 Share Posted October 31, 2019 vor 29 Minuten schrieb Eric Danvers: Does anyone know how to detect a change in Locomotive speed? As far as I know, you cannot detect it. You may need to monitor the speed at regular intervals. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now