Hello fellow gamers,
I've recently started writing a script which adds the volume of energy cells in my ships cargo bay to the name of my ship using the "Advanced Informations in Ship Names" plugin.
I'm having a bit of trouble though. I wonder if someone with more experience could help me?
The code I am using is as follows:
Arguments:
* 1: Message , Var/String , 'Number of energy cells in'
* 2: ECellQuantiyFighter , Value , 'ECell Quantity'
* 3: FighterShipName , Var/String , 'fighter wing leader-nova'
Code:
001 $FighterShipName = 'fighter'
002 $ECellQuantiyFighter = [PLAYERSHIP] -> get volume of ware Energy Cells in cargo bay
003 $Message = 'Number of ECells in fighter - %s'
004 write to player logbook: printf: fmt=$Message, $ECellQuantiyFighter, null, null, null, null
005 $Scriptname = 'Hello'
006 @ = [THIS] -> call script 'lib.tk.ship.ext.names.cmd' : ship=[THIS] Scriptname=$Scriptname extended name addon=$ECellQuantiyFighter
007 return null
When i run the script, a new log entry is added which correctly displays: "Number of ECells in Fighter - 996"
However, the name of the ship i'm in doesnt change.
What am I doing wrong? Any help would be greatly appreciated.
Display energy cell volume in ship name
Moderators: Scripting / Modding Moderators, Moderators for English X Forum
-
- Posts: 74
- Joined: Tue, 11. Nov 03, 17:25
Display energy cell volume in ship name
There is no victory without sacrifice.
-
- Posts: 5095
- Joined: Tue, 9. Jan 07, 22:04
-
- Posts: 960
- Joined: Wed, 20. Sep 06, 09:57
I don't know this script you're using: lib.tk.ship.ext.names.cmd, but it seems to be a problem with this script (I couldn't find the script, so it's just blind guesses).
Your best bet is debugging, I guess. Look if the ship ever gets renamed. Maybe the called script doesn't allow to rename the playership.
Have you tested your script with a ship you're not in ?
Your best bet is debugging, I guess. Look if the ship ever gets renamed. Maybe the called script doesn't allow to rename the playership.
Have you tested your script with a ship you're not in ?
-
- Posts: 74
- Joined: Tue, 11. Nov 03, 17:25
Okay, i've changed the code to use [PLAYERSHIP]. It now appends the ship name to add the number of ECells in the freight bay of the player ship.
The next step is to extend it to other ships. I assume, you can just use a string variable as the ship name. Anyway, this is the code i'm using:
Arguments:
* 1: ECellQuantityPlayership , Value , 'Returns quantity of ECells in ps'
* 2: ECellQuantityPassenger , Value , 'Returns number of ECells in pass'
* 3: ECellQuantityFighter , Value , 'Returns number of ECells in figh'
Code:
001 $ShipNamePassenger = 'passenger-iguana'
002 $ShipNameFighter = 'fighter wing leader-nova'
003 $Ware = 'Energy Cells'
004 $ECellQuantityPlayership = [PLAYERSHIP] -> get volume of ware $Ware in cargo bay
005 $ECellQuantityPassenger = $ShipNamePassenger -> get volume of ware $Ware in cargo bay
006 $ECellQuantityFighter = $ShipNameFighter -> get volume of ware $Ware in cargo bay
007 $Scriptname = 'NULL'
008 @ = [THIS] -> call script 'lib.tk.ship.ext.names.cmd' : ship=[PLAYERSHIP] Scriptname=$Scriptname extended name addon=$ECellQuantityPlayership
009 @ = [THIS] -> call script 'lib.tk.ship.ext.names.cmd' : ship=$ShipNamePassenger Scriptname=$Scriptname extended name addon=$ECellQuantityPassenger
010 @ = [THIS] -> call script 'lib.tk.ship.ext.names.cmd' : ship=$ShipNameFighter Scriptname=$Scriptname extended name addon=$ECellQuantityFighter
011 return null
The problem is, X2 crashes to desktop when i run this script. It works fine if I take it back to just renaming the player ship.
The next step is to extend it to other ships. I assume, you can just use a string variable as the ship name. Anyway, this is the code i'm using:
Arguments:
* 1: ECellQuantityPlayership , Value , 'Returns quantity of ECells in ps'
* 2: ECellQuantityPassenger , Value , 'Returns number of ECells in pass'
* 3: ECellQuantityFighter , Value , 'Returns number of ECells in figh'
Code:
001 $ShipNamePassenger = 'passenger-iguana'
002 $ShipNameFighter = 'fighter wing leader-nova'
003 $Ware = 'Energy Cells'
004 $ECellQuantityPlayership = [PLAYERSHIP] -> get volume of ware $Ware in cargo bay
005 $ECellQuantityPassenger = $ShipNamePassenger -> get volume of ware $Ware in cargo bay
006 $ECellQuantityFighter = $ShipNameFighter -> get volume of ware $Ware in cargo bay
007 $Scriptname = 'NULL'
008 @ = [THIS] -> call script 'lib.tk.ship.ext.names.cmd' : ship=[PLAYERSHIP] Scriptname=$Scriptname extended name addon=$ECellQuantityPlayership
009 @ = [THIS] -> call script 'lib.tk.ship.ext.names.cmd' : ship=$ShipNamePassenger Scriptname=$Scriptname extended name addon=$ECellQuantityPassenger
010 @ = [THIS] -> call script 'lib.tk.ship.ext.names.cmd' : ship=$ShipNameFighter Scriptname=$Scriptname extended name addon=$ECellQuantityFighter
011 return null
The problem is, X2 crashes to desktop when i run this script. It works fine if I take it back to just renaming the player ship.
There is no victory without sacrifice.
-
- Posts: 960
- Joined: Wed, 20. Sep 06, 09:57
Code: Select all
001 $ShipNamePassenger = 'passenger-iguana'
002 $ShipNameFighter = 'fighter wing leader-nova'
First thing to came in my mind. But as I said before: best way to find out where your script goes wrong is debugging.
hth,
Chris
-
- Posts: 74
- Joined: Tue, 11. Nov 03, 17:25
How else would I specify ships without using strings? Do I actually have to design the script so the user is forced to select a ship from in a sector like XaiCorps RESUPPLY script?
Anyway, I will do as yoi suggested and try debugging it. Thanks for the help so far
.
Anyway, I will do as yoi suggested and try debugging it. Thanks for the help so far

There is no victory without sacrifice.
-
- Posts: 960
- Joined: Wed, 20. Sep 06, 09:57
There are several possibilities:
First, you could use one of the 'find ship' instructions. But it's not sure, it will pick the right ship in all circumstances.
I think it's much better to run your script as a command from the ship menu: you give an order to a ship to rename itself.
I'm not sure if I understand your extension. You want the number of energy cells a ship is actually carrying to appear in the name of this ship?
Then the second way is much easier to handle.
You can start (and optionally stop) the renaming procedure for each ship. If you buy or capture a new ship and want it to be renamed, no need to change scripts.
The script could look like this:
The local variable is not necessary, it's there if you want to stop the command and restart it again (this part is missing). In my opinion, the above script isn't really useable. But it works on any ship of my ships.
If you want to know how to bind a script to the command menu, look at the MSCI handbook. There's an example.
hth.
Chris Gi
First, you could use one of the 'find ship' instructions. But it's not sure, it will pick the right ship in all circumstances.
I think it's much better to run your script as a command from the ship menu: you give an order to a ship to rename itself.
I'm not sure if I understand your extension. You want the number of energy cells a ship is actually carrying to appear in the name of this ship?
Then the second way is much easier to handle.
You can start (and optionally stop) the renaming procedure for each ship. If you buy or capture a new ship and want it to be renamed, no need to change scripts.
The script could look like this:
Code: Select all
001 $LocalNameVar = 'OriginalName'
002 $Name = [THIS] -> get local variable: name=$LocalNameVar
003
004 if not $Name
005 $Name = [THIS] -> get name
006 [THIS] -> set local variable: name=$LocalNameVar value=$Name
007 end
008
009 while [TRUE]
010 $Name = [THIS] -> get local variable: name=$LocalNameVar
011 $Amount = [THIS] -> get true amount of ware Energiezellen in cargo bay
012 $NewName = sprintf: fmt='%s %s EC', $Name, $Amount, null, null, null
013 [THIS] -> set name to $NewName
014 @ = wait randomly from 5000 to 10000 ms
015 end
016 return null
If you want to know how to bind a script to the command menu, look at the MSCI handbook. There's an example.
hth.
Chris Gi
-
- Posts: 74
- Joined: Tue, 11. Nov 03, 17:25
Wow, thats a really nice solution. Very clean.
I've got the script to rename the ships I want renamed. I actually used normal variables with the "select ship owned by player" command. It is very limted of course, because you have to change the script to add more ships but it will do for now.
So the last part is to add this command to the Adv Jumper script: "mhordes.freejump".
So I used this: @ = [THIS] -> call script 'a.energy.report' : volume of energy in cargo bay=null volume of energy in cargo bay=null volume of energy in cargo bay=null volume of energy in cargo bay=null
But do I have to retype the trade commands which store the volume of energy cells for each ship in the script (mhordes.freejump)? Surely the whole point of using a script call is not having to retype commands.
I've got the script to rename the ships I want renamed. I actually used normal variables with the "select ship owned by player" command. It is very limted of course, because you have to change the script to add more ships but it will do for now.
So the last part is to add this command to the Adv Jumper script: "mhordes.freejump".
So I used this: @ = [THIS] -> call script 'a.energy.report' : volume of energy in cargo bay=null volume of energy in cargo bay=null volume of energy in cargo bay=null volume of energy in cargo bay=null
But do I have to retype the trade commands which store the volume of energy cells for each ship in the script (mhordes.freejump)? Surely the whole point of using a script call is not having to retype commands.
There is no victory without sacrifice.
-
- Posts: 74
- Joined: Tue, 11. Nov 03, 17:25
All is good. I've got it to work. I forgot to reinit the script cache so it was loading the old script...
So now the proper script is run everytime a freejump is performed.
I think it would be better to use the script you so helpfully provided though, I dont really want to have to keep editing the script everytime I add new ships to my fleet.
Thanks for all your help.
So now the proper script is run everytime a freejump is performed.

I think it would be better to use the script you so helpfully provided though, I dont really want to have to keep editing the script everytime I add new ships to my fleet.
Thanks for all your help.
There is no victory without sacrifice.