Jump to content

Variable into variable


Empfohlene Beiträge

Hello, (german follows)

I'm searching since a few days without seing the solution...  So, I need your help.

Situation :

I have a track called "section" in which I have the variable "Canton" with the value "section_1"; this value is the name of a variable in the object "itinary".

I have another object called "Itinary" describing the traject for the train; in this object itinary, I have defined the variable "section_1" having the value "section_3" which is the next section.

I need to set the object variable "section.next_section" to the value from the object variable itinary.XX where XX stands for the name found in the variable canton from object "section"

Section.canton = section_1 - (section_1 this is the name of the variable from itinary containing the name of the next section for this section)

Object                 variable                             value
Section                canton                              section_1
itinary                  section_1                          section_3

Event
Train enters track               Section
No conditions
Actions :
  1  set variable A =
$((_Trigger2.data)._Name).canton                                                          ==>  A = section_1 (= name of the variable in itinary)
  2  set variable $((_Trigger2.data)._Name).next_section = $(itinary._Name).????                ==> next section = section_3
                                                       where ???? must be the variable's name which value is contained in the variable A

how to build this action?

Thank you for your help
regards

 

Hallo, folgt

Ich suche seit ein paar Tagen ohne die Lösung zu sehen ... Also brauche ich deine Hilfe.

Situation :

Ich habe eine Spur namens "section", in der ich die Variable "Canton" mit dem Wert "section_1" habe. Dieser Wert ist der Name einer Variablen im Objekt "itinary".

Ich habe ein anderes Objekt namens "Itinary", das den Trajekt für den Zug beschreibt. Ich habe in diesem Objekt itinary die Variable "section_1" mit dem Wert "section_3" definiert, der den nächsten Abschnitt darstellt.

Ich muss die Objektvariable "section.next_section" auf den Wert aus der Objektvariablen itinary.XX setzen, wobei XX für den Namen steht, der im Variablenkanton aus Objekt "section" gefunden wird.

Section.canton = section_1 - (section_1 Dies ist der Name der Variablen aus itinary, die den Namen des nächsten Abschnitts für diesen Abschnitt enthält.)

Objekt                 variablen                           wert

Section                canton                              section_1
itinary                  section_1                          section_3


Event
Train enters track               Section
No conditions
Actions :
  1  set variable A =
$((_Trigger2.data)._Name).canton                                                          ==>  A = section_1 (= Name der Variablen in itinary)
  2
et variable $((_Trigger2.data)._Name).next_section = $(itinary._Name).????                   ==> next section = section_3
                                                       woher ???? muss der Name der Variablen sein, deren Wert in der Variablen A enthalten ist

Wie baut man diese Aktion auf?

Danke für deine Hilfe
Grüße

André

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

Unfortunately for an indirect access you can just peek the name of an object, but not the name of an object variable.
So this leads to nothing:

vor 20 Minuten schrieb ademes:

this value is the name of a variable in the object "itinary"

 

Link zu diesem Kommentar
Auf anderen Seiten teilen

I'd be glad if someone could tell a solution, I'd need it too.
Perhaps, if you can describe the whole situation more detailed, we can find another workaround.
So far, the only solution is a pack of events looking like this:
event: train enters track  condition: variable got value: _Trigger2.canton  value: section_1   action: _Trigger2.next section = $itinary.section_1;
event: train enters track  condition: variable got value: _Trigger2.canton  value: section_x.   action: _Trigger2.next section = $itinary.section_.x;
...

Andy

btw: you don't need to write $((_Trigger2.data)._Name). ,  _Trigger2 is enough.

Bearbeitet von Andy
Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andy,

The purpose is to build a common event able to pilot a train through the succeeding sections of the layout, according to an itinary (traject).  This means that each time a decision has to be taken for the next section to reserve, I would find the name of this next section as the value of the object variable called itinary._Trigger2.  But this combination doesn't work!

In addition, I will assign the same name to all tracks acting as section : the name will be section and this object will have a pointer to an external table called "variable_sec_n" (n varying for each section) where all needed data will reside.  This permits to copy this table easier than if the data are part of the track itself.  So, I hope to have only one event to manage all sections in my layout.  But, as Martin Luther King said : " I had a dream..!".

The itinary to be followed by a specific train  is defined as the object variable itinary in the object train.  So, changing the traject for a train becomes very simple.

Have a look to the event "test" in the following layout used for the different tests I'm doing.  The results of this event are displayed in the center of the layout (value of A / B / C).  However, the value of C is currently coded as $((_trigger1._Name).itinéraire).section_1 where I hope to replace section_1 by the content of another variable and that is the current objective I'm trying to reach.

I hope that it is now clarified for you.  Anyway, thank you for your help.

Regards

André

test itinéraire 2.mbp

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andre'

I had a look at your layout. There is a board that looks like the template for your EM. What I cant find are the objects you labeled as objects and allocated variables to with values. No object by the name section_1 or sec_1.....

ademes.thumb.JPG.f011bbf23a1966451efdc79107ab8fc9.JPG

I noticed the 5 cube-objects named "Variable_sec_1" to 5 with lots of object-variables but can't see those referenced in the EM entries. Likewise I could not find the objects referenced in the EM either. Maybe those cubes should be the objects Section_1 to 5?

Cheers

Tom

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Tom,

This layout is my "laboratory" where I test different thinks.  So, don't be scared if you don't find any logic between the layout and the events.

1. The 5 cubes you discovered are well object containing variables normally attached to a specific track (say section_n) within a block.  The only reason is the following : if those variables were really attached to a track, it becomes impossible to just copy them if the new track is different (straight><curved, long><short,...).  Having independant object solved this problem.

2. The board you discovered there is only a way to remember the syntax.

3. Each block has a track called "section"; their usage is to manage the block mentionning all needed data such as reservation, name, signal, etc...  But, as earlier explained, these object-variables are set into the 5 cubes you discovered and the section track object contains only one variable "section.data", linking that track to its specific cube.  The purpose was to have one and only one event for all "section track", but it seems to be impossible in V4 as discovered earlier in this thema : the variable's name must always be hardcoded and cannot be the value of another variable : VAR1 has the value TRK01 but one may not use $VAR1 as the name of the variable TRK01.  In other words, the syntax $(VARx._Name).$VAR1 is wrong.                                    André

Link zu diesem Kommentar
Auf anderen Seiten teilen

vor 28 Minuten schrieb ademes:

This layout is my "laboratory" where I test

somehow that looks pretty familiar :)

vor 28 Minuten schrieb ademes:

The board you discovered there is only a way to remember the syntax

just like here too ;)

@metallix

vor 30 Minuten schrieb ademes:

.$VAR1 is wrong

that's the one I explained to you. That's not possible. The concept is pretty interesting, but forced to wait. I'm just glad that those things happen more and more.
Still hope that this will be a fluffy place again.

regards
  Andy

notes.jpg

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi André,
this is the easiest solution to the problem. It's this 'event pack' filtering the optional variables.
First switch: Initializes the system, sets the 'object' indirect to the 'switch' Traject1 and feeds that one with a functions name. It also feeds 'return', because in each more switch 'return' gets given to the parameter 'par'.
More switches: always feeds 'par' with 'return' and switches 'object'. 'object' contains Traject1, and that one's function is 'get section'.
The other events are each for one possible variable in Traject1.
With the _Trigger-trick all switches may be possible, so we filter it with a 'Typ' defined in 'Traject1' and the function (here 'get section').
Then the approbiate object variable gets picked depending on the content of 'par' and is given to 'return'.

regards
  Andy

traject.mbp

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andy,

Thank you for your suggestion.  Unfortunatally, this is not what I'm searching as you still hardcode the block names.  However, your reflexion on using soft switches could be the opening of a new way to solve my problem, but I'm just thinking abot that.

I'll come back to you if I find a solution.

Regards

André

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andy

As foreseen, I come back to you with my solution that nevertheless is not perfect.  Just because I discover 2 new things, one good and one bad :

Good : nesting "$" is allowed and it works!
bad : the position for a switch may not be a variable!

Here, please find a layout where :

in yellow, the logic to implement : 3 trains following 3 different trajects through 6 blocks.  The objective of this exercise is to be able to pilot the 3 trains with as few events as possible.  Did I succeed?  That is the question; any suggestion from you will be gratefull.

Regards

André

test trigger.mbp

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi André,
will take a little bit until I understand it. In the meantime: Do I need this missung custom texture? I guess it is some explanation text:

switches & variables: I also came around that problem. not funny.

regards
  Andy

 

andre.jpg

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andy

Here my "solution" concerning the switches;

- I set variables "Crossing_status" and "Switch_status" in the object Traject1 to the desired value, let say 0 fot the switch and 2 for the crossing
- Pressing then the "Kippschalter" switch only ones will change both switches to their correct position.  This only occurs if the switches aren't in the foreseen position yet.  If they are yet in the wanted position, nothing happens.

I hope to be able to use that events for all switches and crossings that are present on my layout by using the nested $ values.

what do you think about it?

Regards

André

Trajet-1_Andy.mbp

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andrè,
took a little time for the reply, but I'm still very busy analyzing the logfiles of my own layout (and creating helping programs for that) - and that's a lot.
As you know, my concept follows a similar idea about premade trajects, still there are differences. I like your idea to attach special actions to a traject, this probably will later help to stop and wait for un/loading stuff, getting coal/water/fuel or processing the doors of an engine shed after using a turning platform. This is still hardcoded in my layout. It's an important thing for a flexible layout. There are more things one should think about, especially about timing. If you got a whole plan with more trajects for a train, what would you prefer? a) using a fix time to leave a station, b) wait for an amount of minutes, c) wait for another event, d) leave immediately after performing another attached manoeuvre.
Remember, there's also the need to preserve paths and make decision what to do, if there's a reserved block on the way. So you got some similar options in that case.

What we can do now, is to think about those things, collecting them.
But makes no sense to implement that now. Those are the things that will change in the new version.
Also, there's the good question if that should be an open discussion to create a highly flexible universal system that can be used by the most layouts and everyone who isn't a master of programming. I've always been roughly blocked writing about this, so gave it up before new things are available.
So - we could plan a flexible data-system, but cannot be sure if that can be realized.

The other thing is your 'crossing status'-problem.
The 'switch-status' is no problem, that one is correct.
But - for the 'crossing status' you use three event in a row to check about the status and if needed switch again.
That one will not work the way you intended to have it!
In the beginning of an ev-cycle, there's an important thing you have to know:
all events are checked if they happen and if their conditions are fulfilled in kind of a locked state for events and variables and whatever needed.
This also includes kind of multiplying events if you are using the 'trigger'-trick.
Having that done the actions will happen for all things that got a 'true' now.

That means: either the three crossing-state events will happen not at all, or all three at once, but never just one or two times.
If you now make tables what can happen, you'll see the problem.
In addition, I don't know if it is safe to assume that state '2' always switches the same path as state '0' and '3' always equals exactly '1'.

regards
  Andy

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andy,

Thank you for your answer and to take time looking at my problems.

The questions are now :

1. What kind of system am I expecting to build.  I'm not ready for building something like MBS; I just want to create my layout with as few efforts as possible.  This means, for example, not duplicating event if this can be done another way.  Now, if the ideas can help other 3D users on their layouts, it will be great!
Therefore, I plan to write a kind of proposal document where I will try to explain my vision and how to reach it; this document should be reviewed by authorized people in order to check if it is realist and also if some of the ideas aren't yet foreseen in the next version of 3D.
In particular, I want to explain what is a traject for me and what are the components needed to build a traject

2. I don't understand what you mean when you say :" all events are checked if they happen and if their conditions are fulfilled in kind of a locked state for events and variables and whatever needed".
I've learned somewhere in the forum, but also in the Wiki, that there is no logic in the execution of the events : these are executed one after each other in the sequence they appear in the EV cycle.  This cycle is executed from top to bottom with no loop in it, skipping the events that are disable.  If this is not true, then it is time to explain in details how it works.
In particular, using the "Trigger" variable names must avoid any
equivocal ; one must be sure that the "Trigger" he is pointing to is the good one.
Where you are right concerns the execution time; if two events are executed in sequence and if the result of the action in the first one is supposed to be tested in the second one, care must be taken and, maybe, try to have time in between.  In other words, execute the 1st earlier when possible.
3. You also write : "
assume that state '2' always switches the same path as state '0' and '3' always equals exactly '1'. " : it is not the purpose.  If a switch may have up to 4 possible routes defined by 4 positions, I assume that the 4 positions of the crossing may be used to direct the train to the correct corresponding route.  If a route does'nt permit to the train to travell over the crossing to the defined route, than the train must stop and this must be considered as : "the switch is not in the correct position and the train may not go forward".
But, I agree with you that this is not necessary the best (good) solution.  But I don't see others..!                                                                                                                                    Regards  André                                                                                                                                       

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi André,

about 1.)
it's here really not easy to find the balance between efficiency and complexity.
having some kind of a programmed 'engine' means after all that you waste time by calculating unused stuff.
optimize it, and you will miss the one or other thing sooner or later, because usually such a MBS-layout is in work forever.
try to make changes in optimized code, and you'll get crazy. murphy says you will be on the wrong side anyways...

about 2.)
those things are already explained, unfortunately not in the Wiki and just in german.
To the user, things happen in one sequence, that's true, but at runtime, there's some kind of a splitting and that's why the behaviour is something different.

Look at this, imagine the event happens, we just take a look at the conditions:

1.event:   if (variable < 0) variable = 0;
2.event:   if (variable=0) haveaction;

with a variable less 0, you expect that the first action sets variable = 0, so that the condition in the 2nd event is fulfilled, you 'haveaction'.
But MBS works another way! It first checks all conditions and you get with variable < 0:

1. true
2. false

what happens now in this cycle is:  the first line will set variable = 0; because it's 'true', but the second one isn't executed in this cycle anymore it's 'false'! You don't get 'haveaction'! Test it!

That's why I say, with your three identical statements, the crossing switches three times at once, or not at all. Neither one time, nor two times!

about 3.)
first thing is, 0/1 and 2/3 are similar, not 0/2 and 1/3, my (first) fault: (I really have to checkout my layout for this!!! I smell an unspotted bug!)
second thing is: you are right with the activated route. i never really spotted that using automatic switch correction on my trains :$

regards
  Andy

Link zu diesem Kommentar
Auf anderen Seiten teilen

Hi Andy

I'm lost...  And completely disapointed.

1.  This means that I will stop searching solutions where there are none.

2. Could you tell me where I can found that explanation, no matter if it is in german; translators exist for that.

3. Why 4 positions in that case?  I don't understand the logc behind.

Anyway thank you again Andy.

Regards

André

Link zu diesem Kommentar
Auf anderen Seiten teilen

Link , please translate BahnLand's final explanation.

Did you try your own sample?

Am 25.3.2019 um 10:50 schrieb ademes:

In position 0 the crossing switch is 3 after switching,
in position 1 it is 0
in position 2 it's the value it should have, no switching
in position 3 is comes out 2.
So it doesn't stop at the desired position, it switches 3 times. Three identical events, three times identical behaviour - it's like Brexit voting.

What should I say more?

Link zu diesem Kommentar
Auf anderen Seiten teilen

vor 15 Stunden schrieb Andy:

(I really have to checkout my layout for this!!! I smell an unspotted bug!

Ah yes, I already modified the crossing, reducing it to 2 states, activating 2 routes for each state B| That way it fits to the system.

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