Question about variables, values, and scripting.
My script that I'm testing the concept with is this:
function onebyone(target) {
target1x1 = target;
}
And the other is this(triggered from a logic auto):
target1x1 <- target;
Does anyone know why this isn't working, and what I need to know to get it working? There may be a way to do this without scripting, but I want to use this to learn.
function onebyone() {
target1x1 = "Track_1x2";
}
And the other one that I added to declare the variable as a global variable is this:
target1x1 <- "Track_1x1";
It still isn't working. When I test it in the map, I get this error:
AN ERROR HAS OCCURED [the index 'target1x1' does not exist]
I believe my main problem is that what I'm trying to use as a variable is not acting as a variable, but instead the specific target itself. Not in my code, but in hammer. Specifically, I am trying to be able to dynamically change the "next stop target" of a path_track by putting a variable in the place of the value. I'm not sure if it's possible, but if it is, I'm convinced that I'm not doing it right.
Variables have three types of scope: local, entity-global, and map-global (I'm sure there are better terms for this, but I don't know them).
Local (goes out of scope when its block ends):
local x=20;
Entity-global (available for all functions in an entity's script):
x <- 20;
Map-global (available for everything in your map):
::x <- 20;
I'm guessing your two functions are executed on different entities.
To make it even more interesting, only use three entities in your VMF: a player start, a script, and a logic_auto. 
If I'm getting this right you should be able to use ToggleAlternatePath and EnableAlternatePath to switch to new route. And use a filtered trigger to send these inputs to your path_track ...
Alternatively if you want more than two directions why not play with the parenting options? If your platforms are parented to the train, have multiple paths and trains and "on pass" set the platform to parent the next train... maybe some logic_case/branches to set an AddOutput>OnPass>SetParent>Platform>New Train on the path track kinda stuff .... not sure how this would work out but it might be a good start to solve your problem using a hammer based solution instead of scripting.. because I've got no experience with squirrel so can't help you there. ...
You'd only need three.
|
1
/ \
2 3
/ \ / \
| | | |
FelixGriffin wrote:
You'd only need three.```
|
1
/ \
2 3
/ \ / \
| | | |```
oh, That would be a lot more effective than what I was imagining.