Help with a basic script

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Help with a basic script

Post by albazeus » Sat, 7. May 16, 23:32

Hi, I'm trying to understand how scripting works. I want to move my ship to the position (0,40k,0). Here is the code:

Code: Select all

display subtitle text: text='Moving to (0,40k,0)' duration=5000 ms
@ = [PLAYERSHIP]-> move to position: x=0 y=40000 z=0 with precision 100 m
return null
But my ship just go straight at full speed. Also the speed is locked.
I've read the page 51 of the handbook but got no clue.

Anyone so kind to explain what's wrong in the code?
Thanks

User avatar
Joubarbe
Posts: 3596
Joined: Tue, 31. Oct 06, 13:11
xr

Post by Joubarbe » Sun, 8. May 16, 08:54

Take a look at the script !ship.cmd.movetoposition.std to see how it's done in the game.

Your script won't work on the PLAYERSHIP, but will work on any other ship.

albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Post by albazeus » Sun, 8. May 16, 09:48

Hi Joubarbe, thanks for the info and for the tutorials on youtube.
I have to wait till this evening to look at it.
Now that I think of it, it doesn't make sense to use PLAYERSHIP. Maybe using [THIS]? I'll do some tests.

Thanks!

User avatar
Joubarbe
Posts: 3596
Joined: Tue, 31. Oct 06, 13:11
xr

Post by Joubarbe » Sun, 8. May 16, 12:29

[THIS] is the object the script is running on. If you have a way to run this script on a ship you targeted some way, yes, use [THIS]. It's probably what you wanna do.

User avatar
jack775544
Posts: 1117
Joined: Tue, 13. Dec 11, 09:27
x4

Post by jack775544 » Sun, 8. May 16, 12:55

If you run a script manually from the SE window in game then you can select the target for the script to be run on and therefore changing [THIS]
1940s - Various "computers" are "programmed" using direct wiring and switches. Engineers do this in order to avoid the tabs vs spaces debate.

albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Post by albazeus » Tue, 27. Feb 18, 20:44

Sorry to necro this post, but I forgot how I solved it (if ever).

Using [THIS] is good only if I run the script manually, but not when using an hotkey.
Is there a way to do it?

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 20550
Joined: Mon, 15. Nov 04, 00:26
x4

Post by Cycrow » Tue, 27. Feb 18, 21:44

if using a hotkey, then the script is run globally, so [THIS] will be null, and therefore not work.

what you need to do is create 2 scripts, one is the hotkey script, thats called when the hotkey is pressed, the other is the command script that does what you need.

the command script would have the, [THIS] -> move to position command in

then in the hotkey script, use START [PLAYERSHIP] -> call script 'the command script name'

albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Post by albazeus » Wed, 28. Feb 18, 01:08

ok so I have my scrypt, aa.moveto50k.xml:

Code: Select all

display subtitle text: text='Moving to coordinates (0,50k,0)' duration=5000 ms
= [THIS]-> move to position: x=0 y=50000 z=0 with precision 2000 m

return null
I created the hotkey script, aa.hkcall.moveto50k.xml:

Code: Select all

start [PLAYERSHIP] -> call script 'aa.moveto50k' :
return null
Then I have the setup script, aa.setup.moveto50k.xml:

Code: Select all

$key = get global variable: name='moveto50k'
if not $key
$key = register hotkey 'Move to (0,50k,0)' to call script 'aa.hkcall.moveto50k'
set global variable: name='moveto50k' value=$key
end
return null
But still, if I press the hotkey, I get the message 'Moving to coordinates (0,50k,0)' but my ship doesn't move. What's wrong?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13817
Joined: Sun, 20. Nov 05, 23:45
x4

Post by UniTrader » Wed, 28. Feb 18, 23:19

if i remember the movement scripts correctly the "move to" command has to be put in a loop (with Destination reached as exit condition).
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Post by albazeus » Thu, 1. Mar 18, 01:35

mmm, this script is starting to prove quite difficult for me. Copying from another script, I updated my aa.moveto50k.xml:

Code: Select all

display subtitle text: text='Moving to coordinates (0,50k,0)' duration=5000 ms
*= [THIS]-> move to position: x=0 y=50000 z=0 with precision 2000 m
while 1
$flret = [THIS]-> move to position: x=0 y=50000 z=0 with precision 2000m
if $flret != [FLRET_INTERRUPTED]
display subtitle text: text='Break!!' duration=5000 ms
break
end
= wait randomly from 100 to 200 ms
end
return null
but it doesn't work. I see the 'Break!!' message.
I noticed that if I run aa.hkcall.moveto50k.xml manually, it works and I don't have to select my ship.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13817
Joined: Sun, 20. Nov 05, 23:45
x4

Post by UniTrader » Fri, 2. Mar 18, 15:46

if $flret == [FLRET_INTERRUPTED]
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Post by albazeus » Fri, 2. Mar 18, 17:52

UniTrader wrote:
if $flret == [FLRET_INTERRUPTED]
Thanks for keeping helping me but no, doesn't work.
I think this script is correct, in my opinion the problem is how it's called. :gruebel:

User avatar
Joubarbe
Posts: 3596
Joined: Tue, 31. Oct 06, 13:11
xr

Post by Joubarbe » Fri, 2. Mar 18, 18:10

Don't run your script on PLAYERSHIP if you want to make proper tests.

I have no problem with:

Code: Select all

$aim = get player tracking aim
do if $aim -> exists
  = $aim-> move to position: x=0 y=50000 z=0 with precision 2000 m 

albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Post by albazeus » Fri, 2. Mar 18, 20:07

Joubarbe wrote:Don't run your script on PLAYERSHIP if you want to make proper tests.

I have no problem with:

Code: Select all

$aim = get player tracking aim
do if $aim -> exists
  = $aim-> move to position: x=0 y=50000 z=0 with precision 2000 m 
Sorry guys but I can't get it working... :x
With that script, Joubarbe, the targeted ship starts moving but it can't be stopped. And since your script needs a target, how am I supposed to target my own ship?

I didn't mention it before, I don't know if it's relevant: I'm using Litcube Universe on linux with these mods:
- Mayhem
- ADS (Joubarbian Edition)
- Cycrow cheat package

What the script should do: when I press an hotkey, my ship goes to the coordinates (0,50k,0). I don't need to run it on other ships.

albazeus
Posts: 74
Joined: Fri, 21. Feb 14, 18:21
x3ap

Post by albazeus » Fri, 2. Mar 18, 20:35

Ok, we're getting closer. If I start a new game, it works.

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”