scriptwriting difficulties

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

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

mailleweaver
Posts: 68
Joined: Wed, 4. Nov 09, 05:39
x3tc

scriptwriting difficulties

Post by mailleweaver » Fri, 3. Dec 10, 06:41

Is there any documentation for what each script command/function does and how to use it (besides what's on the Xai-Corp website, which is down)?
I'm having trouble with the skip if {object}--> is of {class} function not working and I was hoping to be able to look it up somewhere.
I'm trying to check if a ship is of the Big Ship class or Huge Ship class and then perform a list of functions on it depending on whether it is of either class. It never skips the next line no matter what kind of ship is the $target.

Here are the relevant parts of the script:

Code: Select all

$target = get player tracking aim
$target.pilot.name = $target->get pilot name

* Eject previous pilot.
$sector = $target->get sector
$x = $target->get x position
$y = $target->get y position
$z = $target->get z position
$xx = $x + 25 
$yy = $y + 0 
$zz = $z + 0 
$astronaut = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
$astronaut->set pilot name to $target.pilot.name
$station = find station: sector=$sector class or type={Station 2016} race=null flags=[Find.Nearest] refobj=$astronaut maxdist=null maxnum=1 refpos=null
if $station->exists
  = $astronaut->fly to station $station
else
  = $astronaut->move around 600000 ms
end
 
* Eject extra crew if ship is Big.
* Crew follows Pilot.
skip if $target->is of class {Big Ship 2073}
  goto label HugeBail
$crew = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew->follow object $astronaut with precision 20 m
$crew2 = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew2->follow object $astronaut with precision 20 m
$crew3 = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew3->follow object $astronaut with precision 20 m
 
* Eject extra extra crew if ship is Huge.
* Crew follows Pilot.
HugeBail:
skip if $target->is of class {Huge Ship 2019}
  goto label finish
$crew = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew->follow object $astronaut with precision 20 m
$crew2 = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew2->follow object $astronaut with precision 20 m
$crew3 = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew3->follow object $astronaut with precision 20 m
$crew4 = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew4->follow object $astronaut with precision 20 m
$crew5 = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew5->follow object $astronaut with precision 20 m
$crew6 = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
= $crew6->follow object $astronaut with precision 20 m
 
* Terminate Script.
finish:
return null
I think I managed to get an Aran to pass the Huge Ship test using a different method but Atmospheric Lifter didn't pass, and no ships would pass the Big Ship test with it. I don't remember for sure, but I think it was:

Code: Select all

$class = $target->get object class
if $class == Big Ship 
  do stuff
end
if $class == Huge Ship 
  do something else
end
What does the get object class function return -- just one class or an array of every class that the object belongs to?

Also, instead of creating a specific number of astronauts for each class, I'd like to be able to create a small random number of astronauts for Big Ship and a large random number of astronauts for Huge Ship, but I couldn't find any script function to create multiple ships based on a number fed into it. Is there a simple way to do that?

And as a side note, will those follow $astronaut instructions work? Somehow I doubt it, but I don't know why I doubt it.

mark_a_condren
Posts: 1385
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren » Fri, 3. Dec 10, 07:55

mailleweaver


Your close, but it is doing what you told it to do.

If it is a 'big ship' skip the next line. What you what is if it is a 'big ship' don't skip the next line. So you just need to change it to,

skip if not $target->is of class {Big Ship 2073}

change the 'skip if' to 'skip if not'.

That way it will skip it if it is not a 'big ship', but if it is it will do the next line. 'skip if not' can be read as 'skip unless'.

As for the follow command, i don't know as i've never tried it using an astronaut. So let us know if it works or not when you get the script working.

MarCon

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Fri, 3. Dec 10, 08:24

@mark
mailleweaver is using the correct skips.

the logic flow using the labels is:
if big ship
else if hug ship
end

@maileweaver
I'd recommend changing your code to:

if $target->is of class {Big Ship 2073}
code for big ships
display subtitle text: text='bigship' duration=5000 ms
else if $target->is of class {Huge Ship 2019}
code for huge ships
display subtitle text: text='hugeship' duration=5000 ms
else
display subtitle text: text='no target or ( not a bigship and not a hugeship )' duration=5000 ms
end
return null

otherwise it looks just fine.
the subtitles will help you determine what is what.


as for random numbers, use a random number generator and a while loop.

if big
$i = random number 2 to 5+1
else if huge
$i = random number 5 to 10+1
else
goto label finish
end
while $i
dec $i =
create astro
follow $astro
end
finish:
return null

djrygar
Posts: 1824
Joined: Mon, 10. Aug 09, 02:09
x3ap

Post by djrygar » Fri, 3. Dec 10, 09:01

h2o.AvA wrote:@mark
if big ship
else if hug ship
end

and this flow is wrong
if ships is of [huge] class, it is also in [big] class, as huge is subset of big

so, you should first check for huge ships, then for big

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Fri, 3. Dec 10, 09:22

Well, there you have it.
Just switch it around to:

if huge
else if big
else
end

User avatar
LV
Sith Lord
Posts: 6362
Joined: Wed, 6. Nov 02, 21:31
x3tc

Post by LV » Fri, 3. Dec 10, 12:12

Just to add a little more

the command has returned some questionable results for me when using 'big ship' class

I tend to get objectclass then define each myself e.g. if class = m2, else if class = m1 etc

in addition big ship also contains TL & TM meaning it picks up ships I rarely want to use on checks
LV's TC Scripts
Readme's For All My Scripts


I felt a great disturbance in the forum, Like millions of voices cried out in terror, then were silenced

si tacuisses, philosophus mansisses

User avatar
apricotslice
Posts: 13737
Joined: Sun, 16. May 04, 13:01
x4

Post by apricotslice » Sat, 4. Dec 10, 07:56

To answer the original question, there is documentation being worked on at the moment in the form of a script command forum.

Its nowhere near complete yet, so is not available to anyone except the development team.

But once its finished, every command will be documented including what is known about it and any quirks it has.

mailleweaver
Posts: 68
Joined: Wed, 4. Nov 09, 05:39
x3tc

Post by mailleweaver » Sat, 4. Dec 10, 08:55

To answer the original question, there is documentation being worked on at the moment in the form of a script command forum.

Its nowhere near complete yet, so is not available to anyone except the development team.
Just saw its sticky "MSCI Reference."
Doh! :headbang: I've had the MSCIHandbook.pdf on my HDD for months. Why didn't I look there? Because I'm stupid and don't associate the Script Editor with MSCI.

I found why the skip instruction wasn't working for me. I'll elaborate when I'm done fixing it and implementing a couple other ideas I had for it.

Edit: Goodness, the more I work on this script, the more I think of to add to it. It's taking forever, but I can't think about anything else until I finish it. My alarm just sounded and I haven't even been to bed yet. I hope I can post it when I'm done -- still waiting for permission since it's an edit of an existing script.

Anyway, here's what the astronaut code looks like now:

Code: Select all

* Eject previous pilot.
$sector = $target->get sector
$x = $target->get x position
$y = $target->get y position
$z = $target->get z position
$xx = $x + 25 
$yy = $y + 0 
$zz = $z + 0 
$astronaut = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
$astronaut->set pilot name to $target.pilot.name
* $station = find station: sector=$sector class or type={Station 2016} race=null flags=[Find.Nearest] refobj=$astronaut maxdist=null maxnum=1 refpos=null
* if $station->exists
* = $astronaut->fly to station $station
* else
* = $astronaut->move around 600000 ms
* end
 
* Eject extra crew if target is Big. Crew follows Pilot.
if $target->is of class {Big Ship 2073}
  * display subtitle text: text='Big ship captured.' duration=5000 ms
  $crew = random value from 2 to 6 - 1
  while $crew 
    dec $crew =
    $crew.member = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
    $crew.name = get random name: race=$owner.race
    $crew.member->set pilot name to $crew.name
    * = $crew.member->follow object $astronaut with precision 50 m
  end
end
 
* Eject extra extra crew if target is Huge. Crew follows Pilot.
if $target->is of class {Huge Ship 2019}
  * display subtitle text: text='Huge ship captured.' duration=5000 ms
  $crew = random value from 6 to 11 - 1
  while $crew 
    dec $crew =
    $crew.member = create ship: type={Argon Space Suit} owner={Neutral Race} addto=$sector x=$xx y=$yy z=$zz
    $crew.name = get random name: race=$owner.race
    $crew.member->set pilot name to $crew.name
    * = $crew.member->follow object $astronaut with precision 50 m
  end
end
I like getting astronauts from both classes when it's a huge ship, by the way.

Except for the While loops (which work beautifully, h2o), this is pretty much what I started with. The problem was in the two Move instructions for the first astronaut. None of the rest of the script would run until the move command was carried out to completion. Another astronaut would be created after the first either docked at a station or 10 minutes passed, depending on if there was a station in the sector. When I was testing Thursday I didn't wait that long for any of my tests except one (which was by accident; I was doing something else at the same time) so I thought the Skip instruction was failing when it hadn't even been run yet. The same applies to the Follow instruction, so I had to just get rid of them and let the astronauts sit still and wait for rescue, death, or enslavement. :twisted:

Now I'm having trouble with another part of the script. I can't get a distance check between PlayerShip and Target to return False if I'm not in the same sector as the target:

Code: Select all

$distance = 26000

* -Wait 15s. Error if the target leaves comm range.
$wait = 3 
while $wait 
  dec $wait =
  = wait 5000 ms
  if $target->exists
    $distance = get distance between [PLAYERSHIP] and $target
    if $distance 
      if $distance > 25000 
        goto label lost
      end
    else
      goto label lost
    end
    $distance = 26000 
  else
    goto label lost
  end
end

* If the target is destroyed or leaves comm range, do this:
lost:
* -Speak: Target lost.
= speak text: page=13 id=1282 priority=0
return null
In Sector, getting outside 25 km makes the IF Distance >25 check return True and the Exists check takes care of target destruction, but if the PlayerShip or Target leave the sector, the distance >25 check always returns False and the IF distance check always returns True so it won't ever "goto label lost." I hoped that the check distance would return Null when one ship is out of sector, but it doesn't. I also tried using IF Not Distance <=25 hoping that it would also return false meaning the opposite of IF Distance >25.

Sorry if I'm rambling. Going to take a nap now.

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Sun, 5. Dec 10, 00:35

One way (may not be the best way, my memory is telling me there is a !script which already does this..but i'm not sure) to fix the follow command is to separate it into another script and then in this script use:
START $newastronaught->call script 'followFirstAstronaught' :


= $newastronaught->call script 'followFirstAstronaught' :
causes the calling script to wait until the called script returns null/var

START $newastronaught->call script 'followFirstAstronaught' :
starts the called script in parallel to the calling script. the calling script continues immediately.


Check to see how the engine normally handles ejected astronauts, I think there is a script that already tells them to go to a station.

try this:
$Tactive = $target->is in active sector
$Texists = $target->exists
$Pactive = [PLAYERSHIP]->is in active sector

if $Texists AND $Tactive AND $Pactive
else
goto label
end

return null


might be able to drop $target->exists since if it doesn't exist it probable isn't in the active sector.

mark_a_condren
Posts: 1385
Joined: Wed, 3. Aug 05, 05:05
x3tc

Post by mark_a_condren » Sun, 5. Dec 10, 06:51

My alarm just sounded and I haven't even been to bed yet.
I have no idea how you could have let that happen .... :roll:


I hope I can post it when I'm done -- still waiting for permission since it's an edit of an existing script.
Who's script? and which script of theirs are you modding?

MarCon

mailleweaver
Posts: 68
Joined: Wed, 4. Nov 09, 05:39
x3tc

Post by mailleweaver » Sun, 5. Dec 10, 21:49

It's the Ship Hijacker by Nividium.

mailleweaver
Posts: 68
Joined: Wed, 4. Nov 09, 05:39
x3tc

Post by mailleweaver » Sun, 12. Dec 10, 09:57

Thanks, h2o.AvA, your suggestions were a big help.
h2o.AvA wrote:One way (may not be the best way, my memory is telling me there is a !script which already does this..but i'm not sure) to fix the follow command is to separate it into another script and then in this script use:
START $newastronaught->call script 'followFirstAstronaught' :


= $newastronaught->call script 'followFirstAstronaught' :
causes the calling script to wait until the called script returns null/var

START $newastronaught->call script 'followFirstAstronaught' :
starts the called script in parallel to the calling script. the calling script continues immediately.
I didn't find a !script that did just what I wanted, but one was close. I copied !move.movetosafestation and then altered it to fit my needs for both the pilot and crew members.
h2o.AvA wrote:Check to see how the engine normally handles ejected astronauts...
How would I check to see how the engine normally handles anything? I'd like to see how it handles notoriety loss for various scenarios without playing out each scenario myself. I've done all kinds of poking about in the vanilla scripts but can't find what controls it.
h2o.AvA wrote:try this:
$Tactive = $target->is in active sector
$Texists = $target->exists
$Pactive = [PLAYERSHIP]->is in active sector

if $Texists AND $Tactive AND $Pactive
else
goto label
end

return null


might be able to drop $target->exists since if it doesn't exist it probable isn't in the active sector.
I ended up using:

Code: Select all

if [PLAYERSHIP] -> is in same sector as $target
 check distance
else
 goto label lost
end
I found "is in same sector" while looking for "is in active sector" and decided to use it instead since I didn't have to define more variables for it.

PS. I have gotten permission from Nividium to post the script, so I will once it's done.

User avatar
s9ilent
Posts: 2011
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Sun, 12. Dec 10, 10:18

Hi mailleweaver

Firstly, there is a difference sector and environment. If I'm docked at an argon ship yard in Argon Prime, my sector is Argon Prime, my environment is the shipyard.

So what you should be doing is,
if [ENVIRONMENT] != $playership.environment
... do stuff, e.g. break ....
end

Note [ENVIRONMENT] is [THIS] -> get environment






Secondly, (this is a personal preference thing) I find it easier to read code when you use (what I call) a fail out scenario.

i.e. rather then
while
-if
--if
---if
*** Critical section of code is here ***
---else
---end
--else
--end
-else
-end
end
end

I think its better to do
while
-if not
....
-end
-if not
....
-end
-if not
....
-end
*** Critical section of code is here ***
end



As it is far easier to read whilst debugging.












Thirdly w.r.t the very top piece of code, how your if class wasn't working.
Classes are heirachial (is that a real word?)
i.e.
m1 belongs to big ship
belongs to movable ship
belongs to ship
belongs to movable object
belongs to object

When you do
$var = $ship -> get class
It will usually return the "final" or bottom most class. i.e. Class M1
And naturally, class M1, is not equal to class Big Ship


However, running the script command
$ship -> is of class $class
Does follow the hierarchy tree.
i.e. if $ship is argon one.
$ship -> is of type big ship = true

h2o.Ava
Posts: 317
Joined: Sun, 12. Oct 08, 04:04
x3tc

Post by h2o.Ava » Sun, 12. Dec 10, 10:36

@silent
Using the fail out may be easier to read, however it uses more resources.

The script will always check every if, whereas in nested ifs if the first if fails then all the other ifs are skipped. (oh man.. if grammar is funny)

A few lines of code isn't much, however every line in every script out there adds up, eventually dinging performance.

User avatar
s9ilent
Posts: 2011
Joined: Wed, 29. Jun 05, 01:45
x4

Post by s9ilent » Sun, 12. Dec 10, 12:38

The idea of the fail out, is if you fail a condition, you break/continue/goto, so it doesn't keep going on with the rest of the code so it does not use extra resources.

Post Reply

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