EnglishGermanFrenchRussianItalianSpanish
Log inRegister
 
Help with a basic script
Post new topic Reply to topic
View previous topic :: View next topic
Author Message
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Sat, 7. May 16, 23:32    Post subject: Help with a basic script Reply with quote Print

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:
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

Back to top
View user's profile Send private message
Joubarbe





Joined: 31 Oct 2006
Posts: 3127 on topic
Location: France
Thank you for registering your game
PostPosted: Sun, 8. May 16, 08:54    Post subject: Reply with quote Print

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.


_________________
Mayhem - Satellites Monitoring - Internal Distribution Network - ADS (Joubarbian Edition) - The Joubarbian Toolkit - EasyConnect
Back to top
View user's profile Send private message
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Sun, 8. May 16, 09:48    Post subject: Reply with quote Print

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!

Back to top
View user's profile Send private message
Joubarbe





Joined: 31 Oct 2006
Posts: 3127 on topic
Location: France
Thank you for registering your game
PostPosted: Sun, 8. May 16, 12:29    Post subject: Reply with quote Print

[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.


_________________
Mayhem - Satellites Monitoring - Internal Distribution Network - ADS (Joubarbian Edition) - The Joubarbian Toolkit - EasyConnect
Back to top
View user's profile Send private message
jack775544





Joined: 13 Dec 2011
Posts: 1116 on topic
Location: Australialand
Thank you for registering your game
PostPosted: Sun, 8. May 16, 12:55    Post subject: Reply with quote Print

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.
Back to top
View user's profile Send private message
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Tue, 27. Feb 18, 20:44    Post subject: Reply with quote Print

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?

Back to top
View user's profile Send private message
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)



Joined: 15 Nov 2004
Posts: 20500 on topic
Location: London
Thank you for registering your game
PostPosted: Tue, 27. Feb 18, 21:44    Post subject: Reply with quote Print

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'


_________________
My Scripts | MY X3TC Scripts | X3 Plugin Manager | Custom Gui
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Wed, 28. Feb 18, 01:08    Post subject: Reply with quote Print

ok so I have my scrypt, aa.moveto50k.xml:
Code:
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:
start [PLAYERSHIP] -> call script 'aa.moveto50k' :
return null

Then I have the setup script, aa.setup.moveto50k.xml:
Code:
$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?

Back to top
View user's profile Send private message
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)

MEDAL

Joined: 20 Nov 2005
Posts: 13626 on topic

Thank you for registering your game
PostPosted: Wed, 28. Feb 18, 23:19    Post subject: Reply with quote Print

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 Wink

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help Wink
Back to top
View user's profile Send private message
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Thu, 1. Mar 18, 01:35    Post subject: Reply with quote Print

mmm, this script is starting to prove quite difficult for me. Copying from another script, I updated my aa.moveto50k.xml:
Code:
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.

Back to top
View user's profile Send private message
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)

MEDAL

Joined: 20 Nov 2005
Posts: 13626 on topic

Thank you for registering your game
PostPosted: Fri, 2. Mar 18, 15:46    Post subject: Reply with quote Print

Quote:
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 Wink

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help Wink
Back to top
View user's profile Send private message
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Fri, 2. Mar 18, 17:52    Post subject: Reply with quote Print

UniTrader wrote:
Quote:
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. Thinking

Back to top
View user's profile Send private message
Joubarbe





Joined: 31 Oct 2006
Posts: 3127 on topic
Location: France
Thank you for registering your game
PostPosted: Fri, 2. Mar 18, 18:10    Post subject: Reply with quote Print

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

I have no problem with:

Code:

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



_________________
Mayhem - Satellites Monitoring - Internal Distribution Network - ADS (Joubarbian Edition) - The Joubarbian Toolkit - EasyConnect
Back to top
View user's profile Send private message
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Fri, 2. Mar 18, 20:07    Post subject: Reply with quote Print

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

I have no problem with:

Code:

$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... Mad
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.

Back to top
View user's profile Send private message
albazeus





Joined: 21 Feb 2014
Posts: 69 on topic
Location: Unknown Sector
Thank you for registering your game
PostPosted: Fri, 2. Mar 18, 20:35    Post subject: Reply with quote Print

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

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic Reply to topic
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Control Panel
Login Data
The time now is Sun, 27. May 18, 19:25

All times are GMT + 2 Hours

[ Disclaimer / Impressum ] | [ Privacy Policy / Datenschutz ]

Board Security

Copyright © EGOSOFT 1989-2018
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 0.15577 seconds, sql queries = 30