Jump to content

Ereignis Variable wird gesetzt


Timba

Empfohlene Beiträge

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 zu diesem Kommentar
Auf anderen Seiten teilen

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 zu diesem Kommentar
Auf anderen Seiten teilen

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 zu diesem Kommentar
Auf anderen Seiten teilen

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 zu diesem Kommentar
Auf anderen Seiten teilen

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 zu diesem Kommentar
Auf anderen Seiten teilen

Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren

Du musst ein Benutzerkonto besitzen, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen.

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...