Jump to content

Ereignis Variable wird gesetzt


Timba

Recommended Posts

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

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
1500850184_detecttableinsert.jpg.b16a3731a163a50334adc02243c51bd3.jpg  

Link to comment
Share on other sites

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...