Jump to content

Empfohlene Beiträge

Geschrieben

Hello, 

Sorry I'm here back only to understand / learning something. 

Before the question a short introduction.
In route locking I have also crosses which must be locked. And a static cross doess not have a position. ( unlike a track switch )
Solution : give in the table position 99 to such crosses, so they are handled as another switch,  and trap in the code with an if ... then. Works fine

Code 
  -- lock the switches, crossings 
  for i, Switch in ipairs(t) do
    -- a cross without position has in the list/table position 99
    if   Switch["Position"] ~= 99 then
      Switch["SwitchPoint"].state = Switch["Position"]
    end

    Switch["SwitchPoint"].variables["#TSW Locked"] = true
  end

In a project I forgot to give the crosses the 99 position, they have none as you can see in the table : Route [2]

1091950977_Routelocking.jpg.d21ed63157cf3fc42c695ebc74c5f0bf.jpg

The code is as above, but even when I looked with the analyser, it seemed there was no script error visible, and I did expect one.
And it all works fine ? Is there an error or not, or did I just not seen it ? Do I overlook something ?

As always thanks for reading, super thanks for an answer.

Kind regards, Herman

Geschrieben

Hello Herman,

a simple crossing is not a switch. It therefor has no "state" property.

Unlike double slip switches, which are of course a sort of switch.

Kind regards
Goetz

Geschrieben
3 minutes ago, Goetz said:

a simple crossing is not a switch. It therefor has no "state" property.

Hello @Goetz,

Yes I know that. Of course it has no state to switch. That's why I gave it in the route table position 99 as an non existent state.
The if ... then sees the 99, and there is no change of the state. That works fine.

But now I forgot to give ( in the route table ) to give this 99. I gave no position a

Geschrieben
Just now, Herman said:

But now I forgot to give ( in the route table ) to give this 99. I gave no position a

Sorry, interrupt.

So I forgot the = 99 position.  I wonder why all is still working. 

In     if   Switch["Position"] ~= 99 then , the Switch["Position"] does not exist in the table ( if it is a static cross )
Why is there not an error ? Sorry my question was confusing. 

Herman


      

Geschrieben
11 minutes ago, Herman said:

That's why I gave it in the route table position 99 as an non existent state.

Maybe someone wonders why the cross is in the table. Well it has no state indeed, but still needs locking if the train comes there.
So I wanted to handle switches and crosses in the same manner in the route table. The code then filters out the cross for the state, but still locks correct.

 

Geschrieben
vor 12 Minuten schrieb Herman:

Sorry my question was confusing. 

indeed, it is.

I understand why you want to include the crossing.
But your method seems strange and cumbersome. Why not have a simple "lock" boolean, which you turn on and off?

Geschrieben
Just now, Goetz said:

Why not have a simple "lock" boolean, which you turn on and off?

That's exactly what I do.  It is a simple lock. The switches and static crosses have a boolean in it 

code :

    Switch["SwitchPoint"].variables["#TSW Locked"] = true

Never mind. It's just I do not understand why an non existing "thing" causes no error in the if then else.
There is a misunderstanding about what I'm asking ... :(

However, thanks a lot for your time and answer.

Kind regards,
Herman

Geschrieben
vor 23 Minuten schrieb Herman:

It's just I do not understand why an non existing "thing" causes no error

Probably, because Lua creates variables (and table entries) when they don't exist and you assign a value to them.

At Lua level, the command Switch["SwitchPoint"].state = Switch["Position"] maybe fine.
And Lua won't know that the item in question has no state. The Lua table is merely a copy of the item's properties.

Geschrieben

Hello,

Mostly in this part of the forum there is asked for a solution.
Here it is the other way around. The solution is there, is not cumbersome, and works fine.
Track Switches and Static Crosses are handled the same in the route table. So I needed something to distinguish. 
I took position 99, but it could be whatever. 

But I forgot to implement it in a new project. I forgot to give the crosses a position, it does not exist in the table. And still all is working as before. Strange not ?

I leave it here, sorry I'm not more clear.

Kind regards,

Herman

Geschrieben

Hello @Goetz,

 

1 minute ago, Goetz said:

At Lua level, the command Switch["SwitchPoint"].state = Switch["Position"] maybe fine.

We both do not give up hé.  Nice you come still with an answer.
That's the answer I was looking for. 

Thank you very much indeed !

Nice regards,

Herman

 

 

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...