Random viewing of Locos

I discovered an error in my original code while looking at something else this morning: Vehicle[] LocoList; should be Vehicle[] LocoList = new Vehicle[0];, assuming that I got the syntax correct.

Speaking of syntax, I notice that you have removed the semicolon from the SetCamera line. Is there a reason for this? I also note unbalanced braces; you need an additional close-brace at the end. Unfortunately, I`m a bit unclear on exactly where close-braces need semicolons and where they are forbidden.

Additionally, to operate the rule, the class will require an Init(Asset) method; for something this simple, renaming FocusRandomLoco should suffice.

Don`t forget to tell the config.txt file which script file and what class are required. It won`t work if you forget.

That`s about all I can think of at this time; I have no idea why it doesn`t like the function header. I`ll check back later to see how this is working out for you.

That quote does seem to apply here, doesn`t it?
Yes it does....:)
Thanks for the reply, will do some more . Did not even notice the missing semicolon and the braces.... will have to check those.
Have a appointment later on, so can't do much at the moment. Maybe later
 
Last edited:
Hahaha, I just now got back from one, and I have another event to attend later, so no issues there. You`re welcome; I`m glad to help. I`ll be back later to see how things are going. Meanwhile, I have my Linux install of Trainz almost whipped into shape, and should be able to start doing some real scripting here again soon. I hope.

As for noticing stuff like the semicolons and braces, I have an unfair advantage there because I have Asperger`s Syndrome. Gives me problems in other areas, though.
 
Code:
//==========================================================================================
// File: RandomViewLoco.gs
// Desc:  View Trainz Randomly
//==========================================================================================

include "ScenarioBehavior.gs"
include "TrainzAssetSearch.gs"
//include "KUID.gs"
//include "KUIDList.gs"
//=====================================
// Get List of Trainz
//=====================================
class RandomViewLoco isclass ScenarioBehavior
     {

      public void Init()
      {
      inherited();
      Vehicle[] LocoList = new Vehicle[0];
      Vehicle[] VehicleList = World.GetVehicleList();
                for (i = 0; i < VehicleList.size(); i++)
                {
                Vehicle ThisVehicle = VehicleList[i];
                        if (ThisVehicle.GetVehicleTypeFlags() == ThisVehicle.TYPE_LOCOMOTIVE)
                        LocoList[LocoList.size()] = ThisVehicle;
                        }
  //Select one at random.
  World.SetCamera(LocoList[math.Rand(0, LocoList.size()-1)];
  };

Have done more in the half hour this morning than last night... :)

if it now stuck on line 28, which is the "wold" statment....

more to come..hehehe

my typing stucks sometimes.... that should be "world".

Plus a mending broken ankle does not help....keeps distracting me....
 
Code:
//==========================================================================================
// File: RandomViewLoco.gs
// Desc:  View Trainz Randomly
//==========================================================================================

include "ScenarioBehavior.gs"
include "TrainzAssetSearch.gs"
include "World.gs"
//include "KUIDList.gs"
//=====================================
// Get List of Trainz
//=====================================
class RandomViewLoco isclass ScenarioBehavior
     {

      public void Init()
      {
      inherited();
      Vehicle[] LocoList = new Vehicle[0];
      Vehicle[] VehicleList = World.GetVehicleList();
                for (i = 0; i < VehicleList.size(); i++)
                {
                Vehicle ThisVehicle = VehicleList[i];
                        if (ThisVehicle.GetVehicleTypeFlags() == ThisVehicle.TYPE_LOCOMOTIVE)
                        LocoList[LocoList.size()] = ThisVehicle;
                        }
  //Select one at random.
    World.SetCamera(LocoList[Math.Rand(0, LocoList.size()-1)], 2);
    }
    };

Just about to go out.... Finnaly got the syntax correct...hehe
Now got down to the nitty gritty...NittyGritty-Screenshot
will check back latter....
 
Plus a mending broken ankle does not help....keeps distracting me....
Ouch!

Oops, I guess I had forgotten about things like World.GetVehicleList() having been obsoleted. It should still work (in compatibility mode, anyway), but will probably be rejected if you try to upload it. We would need to write our own version of GetVehicleList using the new async search feature if we want it uploadable.

Variable i not declared: it needs an int i; before the for statement, or the for statement header rewritten as for (int i=0;.... Simple stuff again. This should also clear the remaining errors, as they are based upon a misunderstanding by the compiler regarding the type of i.

Other than this, the worst I can find is weird formatting, but weird formatting doesn`t matter to the compiler, and I`ve already missed a few things that do matter to the compiler. <shrug>
 
Ouch!

Oops, I guess I had forgotten about things like World.GetVehicleList() having been obsoleted. It should still work (in compatibility mode, anyway), but will probably be rejected if you try to upload it. We would need to write our own version of GetVehicleList using the new async search feature if we want it uploadable.

Variable i not declared: it needs an int i; before the for statement, or the for statement header rewritten as for (int i=0;.... Simple stuff again. This should also clear the remaining errors, as they are based upon a misunderstanding by the compiler regarding the type of i.

Other than this, the worst I can find is weird formatting, but weird formatting doesn`t matter to the compiler, and I`ve already missed a few things that do matter to the compiler. <shrug>
Just got back from Physio, looks like my last.....all i got todo is keep up on the exercises....:)

will make a few simple(impossible)hehe adjustments.
 
Code:
//==========================================================================================
// File: RandomViewLoco.gs
// Desc:  View Trainz Randomly
//==========================================================================================

include "ScenarioBehavior.gs"
include "TrainzAssetSearch.gs"
include "World.gs"
//include "KUIDList.gs"
//=====================================
// Get List of Trainz
//=====================================
class RandomViewLoco isclass ScenarioBehavior
     {

      public void Init()
      {
      inherited();
      Vehicle[] LocoList = new Vehicle[0];
      Vehicle[] VehicleList = World.GetVehicleList();
      int i;
                for (i  = 0; i < VehicleList.size(); i++);
                {
                Vehicle ThisVehicle = VehicleList[i];
                        if (ThisVehicle.GetVehicleTypeFlags() == ThisVehicle.TYPE_LOCOMOTIVE)
                        LocoList[LocoList.size()] = ThisVehicle;
                        }
  //Select one at random.
    World.SetCamera(LocoList[Math.Rand(0, LocoList.size()-1)], 2);
    }
 //  Intitalise the varible for the loop
         int t = 4500;

// Want to wait for about 1 minute before selecting the next loco
// this should count down
        for (t-1; t >=0;t--);
 //Select one at random.
 // this time goto tracking camera
    World.SetCamera(LocoList[Math.Rand(0, LocoList.size()-1)], 4);

    };


Mark II starts from int t.

what i want to do is to wait about 1 minute then select another loco...

the loop is where i am stuck at the moment... there is probably an easier way of doing this. :) think i am at the impossible area again....heheheheheeh
 
I forget the details at the moment, and don`t have time to research now either, but there is some kind of sleep()-type call available somewhere, and if that turns out to be incorrect, there are ways to create such a method with messages.

As I alluded to earlier, I had thought that you might just want to select a loco at random, focus on it, and select it for driving, all in a single operation.

As for the usage of this rule, I thought that you might want to fade/cut to black before calling it and fade from black after calling it. There are already rules to handle those, so I didn`t bother trying to include them. There are also rules that can call that sequence in a loop, and rules that delay the execution of the next rule for a specified amount of time.

What you could do with these is insert a Loop rule with the fade/cut rule, the random loco rule, the fade rule, a delay rule, and a test for you clicking on something to terminate the loop, all as children of the Loop rule. Imagine your route loading, with an immediate cut to black so you don`t see things loading, followed by a series of fade in to a random loco, a delay, and a fade out and back in to another loco, which terminates with the current loco selected and ready to drive when you do something (currently unspecified) to terminate the loop and start driving. This can all be accomplished by a judicious use of existing rules and a slight modification of RandomLoco. The largest difficulty I can see is finding a convenient way to terminate the otherwise infinite loop.
 
I forget the details at the moment, and don`t have time to research now either, but there is some kind of sleep()-type call available somewhere, and if that turns out to be incorrect, there are ways to create such a method with messages.

As I alluded to earlier, I had thought that you might just want to select a loco at random, focus on it, and select it for driving, all in a single operation.

As for the usage of this rule, I thought that you might want to fade/cut to black before calling it and fade from black after calling it. There are already rules to handle those, so I didn`t bother trying to include them. There are also rules that can call that sequence in a loop, and rules that delay the execution of the next rule for a specified amount of time.

What you could do with these is insert a Loop rule with the fade/cut rule, the random loco rule, the fade rule, a delay rule, and a test for you clicking on something to terminate the loop, all as children of the Loop rule. Imagine your route loading, with an immediate cut to black so you don`t see things loading, followed by a series of fade in to a random loco, a delay, and a fade out and back in to another loco, which terminates with the current loco selected and ready to drive when you do something (currently unspecified) to terminate the loop and start driving. This can all be accomplished by a judicious use of existing rules and a slight modification of RandomLoco. The largest difficulty I can see is finding a convenient way to terminate the otherwise infinite loop.
The idea that you have is somewhat simular to the idea forming in my mind..:)
will do some research and see what i can come up with... hope your Linux project works out for you....
will let you know what happens.
 
The idea that you have is somewhat similar to the idea forming in my mind..:)
Nice. I`m glad you like (at least most of) it.
will do some research and see what i can come up with... hope your Linux project works out for you....
will let you know what happens.
Thank you. Will do likewise. Currently, I have the program working reasonably well, but need to figure out how to have a Linux program execute a Windows console command in an existing Wine environment. (Almost there, but not quite.) I also have some new-to-me hardware to test, after I do a transplant of my SSD device from one tower to another. I should have working audio afterwards, something I do not have now. Dead motherboard audio and no sound-card-compatible slot available are the issues with my current tower. The new device already has a video card (am told is NVIDIA) and functional motherboard audio, plus may be able to add sound card if needed.

As for research, I`m available again, as soon as I conclude the transplant, but you can better research what rules you already have that might suit. Anything I come up with might not be available until downloaded. <wink>
 
Nice. I`m glad you like (at least most of) it.

Thank you. Will do likewise. Currently, I have the program working reasonably well, but need to figure out how to have a Linux program execute a Windows console command in an existing Wine environment. (Almost there, but not quite.) I also have some new-to-me hardware to test, after I do a transplant of my SSD device from one tower to another. I should have working audio afterwards, something I do not have now. Dead motherboard audio and no sound-card-compatible slot available are the issues with my current tower. The new device already has a video card (am told is NVIDIA) and functional motherboard audio, plus may be able to add sound card if needed.

As for research, I`m available again, as soon as I conclude the transplant, but you can better research what rules you already have that might suit. Anything I come up with might not be available until downloaded. <wink>
why re-invent the wheel.....sometimes can't see the wood for the trees...hehe
 
why re-invent the wheel
....because I have a better wheel design? If you like my scripting skills as demonstrated here, you should see what I`ve got planned for after I get Trainz running on my Linux the way I want it to run. Have a major scripting project planned. You might be able to assemble a few hints if you do a forum search on my posts. Most of my posts aren`t relevant, but the treasure-hunt might be interesting all the same. I have a few gems of hints buried among the general conversation. If you (think you have) figure(d) it out, though, don`t share your conclusions publicly; the project is far from ready. <wink-with-big-grin>
 
the fade in/out rule, does not appear to be working..........
set up all levels to 100 for 30 secs. with the next rule my randomloco and as soon as i goto driver my rule is the first thing that happens.
will see if i can reverse engineer the fade in/out rule and add it to my rule.?
 
I`ve never gotten the fade rule to work for me, but I`ve also never tried. I remembered that there was one, though.

Re-engineer the fade rule? Interesting idea. I wonder if the basic class methods for that are broken, or if it is just the rule. If it is just the rule, reverse engineering it should work. If, on the other hand, the fade in and fade out facility itself is broken, reverse engineering it will probably just prove futile. Either way, attempting to reverse engineer it will tell us where the breakage is.

I saw you reading the thread that I linked to above. I warned you that some of the details could be a tad excruciating. Did you find them so? Do you fancy a bit of a treasure hunt, trying to work out what my project is? Remember, it is not nearly ready enough to discuss in public.
 
While a great idea to reverse the fade rule, a bit beyond me at the moment. Was reading in the scenario & scripting area a way to make it work......it does seems to work as a child rule, but i think the time part of it is broken. Set it for 15 secs. and two minutes later it is still going.???
 
I remember reading the methods required to do this, but I do not recall where they were. That said, they have the feel of something that belongs in World.gs. I'm about ready to work on my project a smidge or two, as I have managed to get jEdit to successfully call TrainzUtil and capture the output, but I`ll keep an eye out for anything relevant. I saw one of your posts in a relevant thread over there. The required parent rule, as stated in that thread, is a rule that I do not recall having even heard about before.
 
Back
Top