I am very new to scripting and just recently figured out how to transfer funds from one factory to another factory. I am now trying to create a simple script that when run will move funds from all my factories to one I specify.
I have tried to use the following code
$Cahoonabakery01 -> set local variable: name= $cahoonabakery01 value= Your Cahoona Bakery 01 [Ore Belt]
I have also tried the same thing using set gloval variable. The value is not holding in that variable and I don't understand why. When I recal the variable its just 0 or null.
For example the following writes 0 to my log book
$CahoonaBakery01Funds=$CahoonaBakery01 -> get money
Write to player logbook value = $CahoonaBakery01Funds
It should be writing the money in that factory since I set the variable to that factory and set the other variable to get the funds of my cahoona bakery factory.
Obviously I am doing something wrong I just do not know what.
Variables for Stations
Moderators: Scripting / Modding Moderators, Moderators for English X Forum
-
- Posts: 8
- Joined: Wed, 21. Jun 06, 17:45
I guess I figured it out.... I ended up using the <RetVar/If><Expression> and just set it to $CahoonaBakery01=Your Cahoona Bakery 01 [Ore Belt]
Is that the only way to set a variable? It seems to me that Set Local and Set Global variable would be the correct way to set a variable?
But anyways I was able to get the correct funds amount written to log book so at least it is working now.
Is that the only way to set a variable? It seems to me that Set Local and Set Global variable would be the correct way to set a variable?
But anyways I was able to get the correct funds amount written to log book so at least it is working now.
-
- Moderator (Script&Mod)
- Posts: 22438
- Joined: Sun, 14. Nov 04, 23:26
set local and global varibles are something different to what you want.
the name=<value> is a string which allows you to attach a certain value to this string and allows you to get the vairble usign the same string.
this is mainly used when you want to access varibles and data between different script files.
if its in the same script, then theres no need to use it.
one way you can do it is to use arguments for the script.
set an argument to something like $station, then set the type as var/station
when u run the script, it will ask you to select a station, so you select your cahoona bakery, then u can use, $funds = $station -> get money
the name=<value> is a string which allows you to attach a certain value to this string and allows you to get the vairble usign the same string.
this is mainly used when you want to access varibles and data between different script files.
if its in the same script, then theres no need to use it.
one way you can do it is to use arguments for the script.
set an argument to something like $station, then set the type as var/station
when u run the script, it will ask you to select a station, so you select your cahoona bakery, then u can use, $funds = $station -> get money
-
- Posts: 8
- Joined: Wed, 21. Jun 06, 17:45
I found out about the arguments the other day but I did not want to have to go through and manually select 8 stations each time I ran the script.
So I figured I could just assign a variable in the script itself to a specific station. The script ended up running great. I had all of my factories credits except 200,000 transfered to my main factory and if there were not 200,000 credits IN a factory my main factory would supply them.
Today I found out that a script won't save when you use this method.
So my goal of having the process of maintaining a balance of 200,000 in all factories by using a "main" factory automated only works if I create the script and do not leave the game. Which is alot of work to do at each beginning of a game/load
Is there any way to work around this? Either making the script select all my factories automatically, or manually saving the script with XML?
Or maybe there is already a scipt out there that does this? Although I would like to make my own to try and understand how it works.
Any help or advice would be greatly appreciated, thanks.
So I figured I could just assign a variable in the script itself to a specific station. The script ended up running great. I had all of my factories credits except 200,000 transfered to my main factory and if there were not 200,000 credits IN a factory my main factory would supply them.
Today I found out that a script won't save when you use this method.

So my goal of having the process of maintaining a balance of 200,000 in all factories by using a "main" factory automated only works if I create the script and do not leave the game. Which is alot of work to do at each beginning of a game/load

Is there any way to work around this? Either making the script select all my factories automatically, or manually saving the script with XML?
Or maybe there is already a scipt out there that does this? Although I would like to make my own to try and understand how it works.
Any help or advice would be greatly appreciated, thanks.
-
- Moderator (Script&Mod)
- Posts: 22438
- Joined: Sun, 14. Nov 04, 23:26
the reason it doesn't save as the scripts dont allow you to access objects directoly
as you can use the scripts in any games, the objects in other games dont exist, or the ids are incorrect
so theres no way to make it save the scripts.
there are 2 things you could do, if you want it on all of you stations
you can jsut get the station array for player stations and run the script on each one in the array.
the other is to create a script that adds stations to the list.
ie, set the argument to a station, and then this script saves the selected station to a global array.
each time you run the script, it adds the station you select to the array
global varibles are saved, so when you load the game next, the stations you added will still be in the array.
then you just need a script to do what ever you want it to
as you can use the scripts in any games, the objects in other games dont exist, or the ids are incorrect
so theres no way to make it save the scripts.
there are 2 things you could do, if you want it on all of you stations
you can jsut get the station array for player stations and run the script on each one in the array.
the other is to create a script that adds stations to the list.
ie, set the argument to a station, and then this script saves the selected station to a global array.
Code: Select all
arguments: $station - var/station - Select Station
skip if $station -> exists
return null
$station.array = get global varible: name = 'station.list'
skip if $station.array
$station.array = alloc array, size = 0
append $station to array $station.array
set global varible: name = 'station.list' value = $station.array
global varibles are saved, so when you load the game next, the stations you added will still be in the array.
then you just need a script to do what ever you want it to
Code: Select all
$station.array = get global varible: name = 'station.list'
$size = size of array $station.array
while $size
dec $size =
$station = $station.array[$size]
... (do what you want with each station)
end