Jump to content
Dad3353

Keywords: a clear explanation needed, please. :-(

Recommended Posts

Good afternoon...

Once again, I'm looking for answers that, I believe, most of you have already found. I've looked at many example layouts, read many posts in the Forum, and consulted the documentation and Help files, but am still confused.
I'm trying to understand the concept of 'keywords'. It may be as simple question of terminology, but I can't even start using them if I've not grasped the concept in the first place. Could someone try to explain, and maybe illustrate, their use in a simple manner, please..? I have a sample layout ('Variations'...) which has two concentric loops, with a train on each. One station halt, with a road crossing at either end. When the trains pass, the crossings should close, then re-open once the trains are clear. The workings are by means of track contacts and barrier animations, using Keywords to address the Events. I've been struggling to repair an anomaly, whereby the left-side barrier works correctly, but not the right-side one, which remains closed.
Could someone please explain to me the various Keywords in there..? They seem to have almost the same name, and I don't understand how they are used. I have always tried to keep names as clear as I can, and not use simple 'a' or 'b' for things, still less identical names. Are these Keywords case-sensitive..? Is 'input' different to 'Input', for instance..? I also see, in this sample layout, conditions which have the same result whether 'True' or 'False'. Is this normal..? The Track Contacts seem to trigger two Events at once; again, is this normal..?
In short, I'd like this simple layout to work, but the real interest is in learning how and why it should work, not simply fixing the issue that there obviously is.
Anyone brave enough to have a look..? Here's the layout 'Variation'...

Guten Tag...

Ich suche wieder nach Antworten, die, glaube ich, die meisten von Ihnen bereits gefunden haben. Ich habe mir viele Beispiellayouts angesehen, viele Beiträge im Forum gelesen und die Dokumentation und Hilfedateien konsultiert, bin aber immer noch verwirrt.
Ich versuche das Konzept der "Schlüsselwörter" zu verstehen. Es mag eine einfache Frage der Terminologie sein, aber ich kann sie nicht einmal verwenden, wenn ich das Konzept überhaupt nicht verstanden habe. Könnte jemand versuchen, ihre Verwendung auf einfache Weise zu erklären und vielleicht zu veranschaulichen, bitte ..? Ich habe ein Beispiellayout ('Variationen' ...) mit zwei konzentrischen Schleifen mit jeweils einem Zug. Eine Station hält an, mit einer Straßenkreuzung an beiden Enden. Wenn die Züge vorbeifahren, sollten die Kreuzungen geschlossen und wieder geöffnet werden, sobald die Züge frei sind. Die Arbeitsweise erfolgt über Track-Kontakte und Barriere-Animationen, wobei Schlüsselwörter verwendet werden, um die Ereignisse zu adressieren. Ich habe versucht, eine Anomalie zu reparieren, bei der die linke Barriere korrekt funktioniert, aber nicht die rechte, die geschlossen bleibt.
Könnte mir bitte jemand die verschiedenen Schlüsselwörter dort erklären ..? Sie scheinen fast den gleichen Namen zu haben, und ich verstehe nicht, wie sie verwendet werden. Ich habe immer versucht, Namen so klar wie möglich zu halten und kein einfaches 'a' oder 'b' für Dinge zu verwenden, noch weniger identische Namen. Bei diesen Schlüsselwörtern wird zwischen Groß- und Kleinschreibung unterschieden. Unterscheidet sich 'Eingabe' beispielsweise von 'Eingabe'? Ich sehe in diesem Beispiellayout auch Bedingungen, die das gleiche Ergebnis haben, ob 'True' oder 'False'. Ist das normal..? Die Track-Kontakte scheinen zwei Ereignisse gleichzeitig auszulösen. wieder ist das normal ..?
Kurz gesagt, ich möchte, dass dieses einfache Layout funktioniert, aber das eigentliche Interesse besteht darin, zu lernen, wie und warum es funktionieren sollte, und nicht einfach das Problem zu beheben, das es offensichtlich gibt.
Jemand, der mutig genug ist, einen Blick darauf zu werfen? Hier ist das Layout 'Variation' ...

Variation.mbp

Thanks in advance for your help

Vielen Dank im Voraus für Ihre Hilfe

Douglas

Edited by Douglas.A.Allen

Share this post


Link to post
Share on other sites
vor 12 Minuten schrieb Douglas.A.Allen:

I'm trying to understand the concept of 'keywords'.

Keywords may be used to apply one code to mutliple objects.

You add a keyword to an object like you would add a variable. Basically, a keyword looks like a variable without a value. Just the name.

Now, when you write code for e.g. a signal, you may choose (at the top of the window) to apply this code to either

  • an individual specified signal
  • multiple specified signals (multi selection)
  • any signal
  • all signals with a specific keyword.

The idea is that you define a behaviour once and apply it to many objects. 

Any object can have multiple keywords. So you may write

  • some code for all signals (e.g. to close them after a train has passed)
  • some code for all block signals (i.e. signals that divide track sections into blocks
  • some code for entry signals
  • some code for exit signals

and every signal will trigger every script applicable, defined by the keywords you attach to it.

It is a very powerful tool. No copy and paste of code needed, when you understand keywords.

Hope that helps?
If not, please let me know and I see if I can demonstrate it in a short video.

Best
Goetz

Edited by Goetz

Share this post


Link to post
Share on other sites

Thanks, Goetz, for the uber-fast reply.

In the example layout I linked, there is a Keyword 'Trains crossing', which seems to be associated with both level crossings. To identify these Keywords (I assume they are, indeed, two distinct Keywords; I don't see them listed as 'Variables', so it's difficult to know where they all might be...) would it not be better to have one named 'N1 crossing' and the other 'N2 crossing'..? Are these Variable names case-sensitive (ie: 'Crossing' would be different to 'crossing'...)..?
By inspecting all the Track Contacts, I can find six Keywords. These are 'open1to2', 'open 1to2', 'Open1to2', 'close1to2', 'close 1to2' and 'Close1to2', Note the slightly different spelling (with or without space, lower or upper case...). Is this a normal way of naming Keywords..? How would one use these in practise to trigger an animation..? Why would one Track Contact want to trigger two of these Keywords at once..?
Maybe I've chosen a bad example with this layout, but so far, it's the simplest one I've found that uses these concepts, but even so, simple as it seems to be, I don't see what's supposed to happen when a train triggers the Keyword. I can understand opening and shutting the barriers, but not through the use of Keywords.
Is my issue not clear..? I know what is supposed to happen (explained clearly in your reply above...), but I've not found a practical, beginner-level example that makes sense. I would start my own, and I'm sure I'll find them useful, but until I understand how they're used, I'm stumbling around in the dark.
Have you got a torch handy..? :/

Danke, Goetz, für die superschnelle Antwort.

In dem von mir verknüpften Beispiellayout gibt es ein Schlüsselwort "Zugübergang", das beiden Bahnübergängen zugeordnet zu sein scheint. Um diese Schlüsselwörter zu identifizieren (ich gehe davon aus, dass es sich tatsächlich um zwei unterschiedliche Schlüsselwörter handelt; ich sehe sie nicht als "Variablen", daher ist es schwierig zu wissen, wo sie sich alle befinden könnten ...), wäre es nicht besser, eines zu haben genannt 'N1 Kreuzung' und die andere 'N2 Kreuzung' ..? Bei diesen Variablennamen wird zwischen Groß- und Kleinschreibung unterschieden (dh: "Überqueren" unterscheidet sich von "Überqueren" ...).
Durch Überprüfen aller Track-Kontakte kann ich sechs Schlüsselwörter finden. Dies sind 'open1to2', 'open 1to2', 'Open1to2', 'close1to2', 'close 1to2' und 'Close1to2'. Beachten Sie die leicht unterschiedliche Schreibweise (mit oder ohne Leerzeichen, Klein- oder Großbuchstaben ...). Ist dies eine normale Art, Schlüsselwörter zu benennen? Wie würde man diese in der Praxis verwenden, um eine Animation auszulösen? Warum sollte ein Track-Kontakt zwei dieser Keywords gleichzeitig auslösen wollen?
Vielleicht habe ich mit diesem Layout ein schlechtes Beispiel gewählt, aber bisher ist es das einfachste, das ich gefunden habe, das diese Konzepte verwendet, aber trotzdem sehe ich, so einfach es scheint, nicht, was wann passieren soll Ein Zug löst das Schlüsselwort aus. Ich kann das Öffnen und Schließen der Barrieren verstehen, aber nicht durch die Verwendung von Schlüsselwörtern.
Ist mein Problem nicht klar ..? Ich weiß, was passieren soll (klar erklärt in Ihrer Antwort oben ...), aber ich habe kein praktisches Beispiel für Anfänger gefunden, das Sinn macht. Ich würde meine eigenen anfangen, und ich bin sicher, ich werde sie nützlich finden, aber bis ich verstehe, wie sie verwendet werden, stolpere ich im Dunkeln herum.
Hast du eine Taschenlampe zur Hand? :/

Douglas

Share this post


Link to post
Share on other sites
vor 14 Minuten schrieb Douglas.A.Allen:

Maybe I've chosen a bad example with this layout

I'm afraid that you have, yes.

The variations in naming the objects and keywords for instance are merely inaccuracies.
And the naming convention which 220hotwheels chose, makes sense, but is neither required nor easy to grasp at first glance.

Let me see if I can come up with a better example.
And if you wish, we could aggree on a time so that we could do this live on Twitch.tv 
That would give you the opportunity to ask questions (using a chat window). Would that appeal to you?

 

Share this post


Link to post
Share on other sites

Hah ..! You're taking a (big ...) risk there ..! I turned 70 a couple of weeks ago, so stuff like 'Twitch TV' are all new to me ..! I'd certainly be willing to give it a try, of course, and thanks for even considering such an event. 3p9T3qx.gif

A word on naming convention, as an aside ... I've been programmin for over half a century, and have developed my own standard system for names in programming languages. I found that three characters was too short, five too verbose, so settled for four characters. Any object to be names will therefore be, systematically, groups of four characters, separated by underscores. Thus, 'Train Station' becomes 'Trai_Stat'. If there's less than four characters, that's fine, too, so 'Big Wagon' becomes 'Big_Wago'. Similar, or multiple, objects can be numbered, so Signal 1, 2 and 3 become, each, Sign_01, Sign_02 and Sign_03 (the numbering length depends on how many there will be ...). I would usually start the name with the type, so would have Engi_Red, Engi_Yell and Engi_Gree, all different engines (locomotives ...).
Obviously I wouldn't expect to find anything so formal in the layouts, many of which pre-date a language at all, but, for my own peace of mind, that's how I'll be thinking as I get past my current usage and onto Lua, later on.
Sorry for the detour; back to my present issue. A simple track, with two engines running back and forth (no need for a loop ...), with two crossings that raise and lower, triggered by Track Contacts, using this keyword principal. Am I being greedy in asking so much ..?

Hang on a minute; I can't expect you to do all the work ..! Here's a mini-layout, with no event or keywords, just the two trains running back and forth. How to get the barriers to work correctly, using Events and Keywords, please ..? ...

Hah ..! You are taking a (big ...) risk there ..! I turned 70 a few weeks ago so things like 'Twitch TV' are all new to me ..! I would of course be ready to try, and thank you for even thinking about such an event. https://i.imgur.com/3p9T3qx.gif [/ img]

By the way, a word about the naming convention ... I have been programming for over half a century and have developed my own standard system for names in programming languages. I found that three characters were too short and five too verbose, so I decided to use four characters. Each object to be named is therefore systematically made up of groups of four characters separated by underscores. Thus 'Bahnhof' becomes 'Trai_Stat'. If there are fewer than four characters, that's fine too, so that 'Big Wagon' becomes 'Big_Wago'. Similar or multiple objects can be numbered so that Signal 1, 2 and 3 become Sign_01, Sign_02 and Sign_03 respectively (the numbering length depends on how many ...). Usually I would start the name with the type, so Engi_Red, Engi_Yell and Engi_Gree, all different engines (locomotives ...). In OOP languages, I would prefix all variables etc. with the range (local, global ...), the type (variable, constant, index ...) and their type (integer, string, Boolean ...), i.e. a A local variable integer representing a green engine becomes lvi_Engi_Gree.
Of course, I wouldn't expect to find anything so formal in the layouts, many of which predate a language at all, but for my own safety I will think so when I get past my current usage and later on Lua.
Sorry for the detour; back to my current issue. A simple track with two engines running back and forth (no loop required ...), with two intersections that are raised and lowered using this keyword principle, triggered by track contacts. Am I greedy when I ask so much?

Wait a minute; I can't expect you to do all the work ..! Here is a mini layout with no event or keywords, just the two trains going back and forth. How to make the obstacles work using events and keywords, please ..? ...

_Test_Keyw_00.mbp

Douglas

Edited by Douglas.A.Allen

Share this post


Link to post
Share on other sites

Wonderful... I'll go over it ll again once I've finished dinner. A great session; thanks enormously.

Wunderbar ... Ich werde es noch einmal durchgehen, wenn ich mit dem Abendessen fertig bin. Eine großartige Sitzung; Vielen Dank.

Douglas

Share this post


Link to post
Share on other sites

Please note the 'Display Name' update. My ID everywhere on t'web is the same 'Dad3353'; 'Dad' is how I'm addressed most in life, '33' =country code for France, where I live, '53' the department code in France 'Lower Normandy...).

Bitte beachten Sie das Update 'Anzeigename'. Meine ID überall im Internet ist die gleiche 'Dad3353'; 'Dad' ist, wie ich im Leben am meisten angesprochen werde, '33' = Ländercode für Frankreich, wo ich wohne, '53' der Abteilungscode in Frankreich 'Niedernormandie ...).

Douglas

Share this post


Link to post
Share on other sites
44 minutes ago, Goetz said:

the layout from the Twitch session.

Twitch result 01.mbp

Almost. We've forgotten that you're using v6, which v5 cannot load..! XHlPYfU.png  Never mind, I'll try to do it from memory.

Fast. Wir haben vergessen, dass Sie v6 verwenden, das v5 nicht laden kann ..! Egal, ich werde versuchen, es aus dem Gedächtnis zu tun.

Douglas 

Share this post


Link to post
Share on other sites
vor 1 Stunde schrieb Dad3353:

Please note the 'Display Name' update.

recognised

After the V6 narrowly missed it's target (just like the V2 did in WWII), I have replaced it with a V5.

Enjoy :)

Share this post


Link to post
Share on other sites

Magnificent..! Such abnegation ..! I've a lot to study, now. I'll be back with more questions once I've absorbed this.
[Terminator] I'll be back...

Großartig ..! Solche Ablehnung ..! Ich muss jetzt viel lernen. Ich werde mit weiteren Fragen zurück sein, sobald ich dies aufgenommen habe.
[Terminator] Ich komme wieder ...

Douglas

Share this post


Link to post
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

×