[X3TC] Script Newbie question: infinite loop

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
PSCO1
Posts: 1087
Joined: Thu, 4. Jun 09, 17:08
x4

[X3TC] Script Newbie question: infinite loop

Post by PSCO1 » Wed, 17. Feb 21, 01:17

Hi there!
Since few days, ive got a problem with creating new scripts on my mod
First, my goal is to change notoriety of all enemy stations (in pirate sectors) at the beginning of the game
(for some reason, I dont find how to configure notoriety of ALL stations in "maps/X3_Universe.xml")
10% of those stations stay hostile, i dont know why...
My script is done to fix that, and this script must be executed 1 time, of course

Second problem: I dont know why some pirate patrols are RED (with notoriety > 10)
So, I created another script to change status of those hostile ships
But of course, when the job is finished, another hostiles pirates respawn with RED status

My big problem actualy is I am forced to insert my CALL commands in "!job.special.idle" script of the vanilla game
if I want to all my scrtipts to work !

Is there a more "conventional" way to setup my scripts ? step by step ?
My objective is to execute 1 time my "pirateStations.notoriety.fix" at the beginning of the game
Then do an infinite loop with my "pirateShips.Notoriety.fix"

Whats the commands I need to use in my "setup" script ?

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Re: [X3TC] Script Newbie question: infinite loop

Post by Joubarbe » Wed, 17. Feb 21, 09:08

PSCO1 wrote:
Wed, 17. Feb 21, 01:17
Whats the commands I need to use in my "setup" script ?
setup.MyScript.xml

Code: Select all

skip if get global variable: name='myScript_started'
  START [NULL]-> call script 'MyScript.MyLoop':
MyScript.MyLoop.xml

Code: Select all


* Task -1 (global).

set global variable: name='myScript_started' value=[TRUE]

while [TRUE]

  if is a new script version available
    START [NULL]-> call script 'MyScript.MyLoop':
    return null
  end

  * Your code here.
  
  = wait 60000 ms

end

return null
Pirates are meant to be hostile, you will have hard times making them proper friends. Also check your own friend/foe configuration, as it can be the cause of them still showing in red.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: [X3TC] Script Newbie question: infinite loop

Post by Cycrow » Wed, 17. Feb 21, 11:12

Pirates are an Independent faction, so not all pirate ships will follow the notoriety level. Pirate bases do the opposite, where they allow docking even if you have bad notoriety with them.

also, with missions, sometimes the target ships created for missions might be of "Enemy Race" but named as if they are from a normal race

PSCO1
Posts: 1087
Joined: Thu, 4. Jun 09, 17:08
x4

Re: [X3TC] Script Newbie question: infinite loop

Post by PSCO1 » Wed, 17. Feb 21, 11:23

Thanks a lot for the reply !

This is very disturbing ! so you can call the script of the same name from the loop IN the same script :o

By my first look of newbie scripter, I expected the script restarted from the beginning of the script on each "while" loop
But with messages tests apparently not, the loop is not break and continue into the loop with endless time
Thats exactly I wanted ! The script detect all RED pirates SHIPS and switch them to FRIENDLIES every 1min
This first version work fine at this moment...

But...
So after that, I tried to put my "stations.check.fix" code outside the loop, just before the "set global variable: ... "
But sadly, something strange happens, I dont understand the logic of the game:

MyScript.MyLoop.xml

Code: Select all

* 1ST PART: My code to get universe sectors array

* 2ND PART: My code to fix notoriety of all pirate STATIONS in the universe

* MY MESSAGES TESTS HERE (To check if 2ND PART work)

set global variable: name='myScript_started' value=[TRUE]

while [TRUE]

  if is a new script version available
    START [NULL]-> call script 'MyScript.MyLoop':
    return null
  end

  * 3RD PART: My code to fix notoriety of all pirate SHIPS in the universe
  
  = wait 60000 ms

end

return null
With added STATIONS.check (new version), at a new game:
The 1ST PART work, no problem (because the 3RD PART work!)
The 2ND PART is skipped by the game, ??? or I missed something ?
Last edited by PSCO1 on Wed, 17. Feb 21, 11:40, edited 1 time in total.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: [X3TC] Script Newbie question: infinite loop

Post by Cycrow » Wed, 17. Feb 21, 11:39

it might not have been skipped, just that setting the stations to enemy may not happen right at the start of the game.

you could add a delay at the beginning to test if that works.

also, i would suggest moving the set global variable to the top of the script, and put yours between that and the start of the while. Thats there to prevent multiple copies of your script from running at the same time.

and yes you can call the same script from within itself, similar to recursive function calling in other languages, however in this case its just to replace the current one with the new version

PSCO1
Posts: 1087
Joined: Thu, 4. Jun 09, 17:08
x4

Re: [X3TC] Script Newbie question: infinite loop

Post by PSCO1 » Wed, 17. Feb 21, 11:56

Mmmm ok, so if I don't see any message tests for the 2nd part, its probably because the variable for the message text is lost ? :?
At least, this variable should be detected and shown as "NULL"
But there is no message... :gruebel:

A delay like "= wait 2000 ms" ?

Thanks Cycrow for the reply ! Its very appreciated !
Last edited by PSCO1 on Wed, 17. Feb 21, 12:01, edited 1 time in total.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22201
Joined: Sun, 14. Nov 04, 23:26
x4

Re: [X3TC] Script Newbie question: infinite loop

Post by Cycrow » Wed, 17. Feb 21, 11:59

without seeing the actual script, it'll be difficult to tell whats going on

you could post it in here, if you open the script file in a web browser it should format it in a readable way

PSCO1
Posts: 1087
Joined: Thu, 4. Jun 09, 17:08
x4

Re: [X3TC] Script Newbie question: infinite loop

Post by PSCO1 » Wed, 17. Feb 21, 12:03

So my script look like that:

Code: Select all

$sectors = array alloc: size=0
$x = get max sectors in x direction
while $x
  dec $x =
  $y = get max sectors in y direction
  while $y
    dec $y =
    $sector = get sector from universe index: x=$x, y=$y
    if $sector != null
      append $sector to array $sectors
    end
  end
end

$size.sectors = size of array $sectors
while $size.sectors
  dec $size.sectors =
  $sector = $sectors[$size.sectors]
* Notoriety
  $sector.owner = $sector->get owner race
  $notoriety = [PLAYERSHIP]->get notoriety to race $sector.owner
* Stations array
  $stations.arr = $sector->get station array from sector
  $size.stations = size of array $stations.arr
  while $size.stations
    dec $size.stations =
    $this.st = $stations.arr[$size.stations]
    if [PLAYERSHIP]->is $this.st a enemy
      if $notoriety > -10 AND $notoriety < 10
        $this.st->set relation against {Player} to {Neutral}
      else if $notoriety > 10
        $this.st->set relation against {Player} to {Friend}
      else if $notoriety < 10
        $this.st->set relation against {Player} to {Foe}
      end
    end
  end
end

  $text = sprintf: fmt='NMCE pirate stations checked (%s)', $this.st, null, null, null, null
  display subtitle text: text=$text duration=10000 ms

set global variable: name = 'NMCE.pirates.check' value=[TRUE]

while 1
  
  if is a new script version available
    START [THIS]-> call script 'plugin.PSCO1.NMCE.relationFixShips' :
    return null
  end
  
  $size.sectors = size of array $sectors
  while $size.sectors
    dec $size.sectors =
    $sector = $sectors[$size.sectors]
* Notoriety
    $sector.owner = $sector->get owner race
    $notoriety = [PLAYERSHIP]->get notoriety to race $sector.owner
* Ships array
    $ships.arr = $sector->get ship array from sector/ship/station
    $size.ships = size of array $ships.arr
    $size.info = $size.ships
    while $size.ships
      dec $size.ships =
      $this.sh = $ships.arr[$size.ships]
      if [PLAYERSHIP]->is $this.sh a enemy
        if $notoriety > -10 AND $notoriety < 10
          $this.sh->set relation against {Player} to {Neutral}
        else if $notoriety > 10
          $this.sh->set relation against {Player} to {Friend}
        else if $notoriety < 10
          $this.sh->set relation against {Player} to {Foe}
        end
      end
    end
  end
  
  
  = wait randomly from 20000 to 30000 ms
  
end

return null

My message code is just to check if the 2nd part work (and this message dont appears)

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Re: [X3TC] Script Newbie question: infinite loop

Post by Joubarbe » Wed, 17. Feb 21, 15:10

Code: Select all

$galaxy = [PLAYERSHIP]-> find all sectors within 100 jumps: Only known sectors=[FALSE]

PSCO1
Posts: 1087
Joined: Thu, 4. Jun 09, 17:08
x4

Re: [X3TC] Script Newbie question: infinite loop

Post by PSCO1 » Wed, 17. Feb 21, 19:12

With this command, it return a NULL value !

But in others plugins scripts, this command is ok... but not in this case :gruebel:
Maybe the game skip some commands at the beginning of a new game ???
Or the script is too fast for the game ? :D

EDIT:
Problem fixed by adding "Wait" (3000 ms) command just after the "set global variable..."

Now the beginning of the script new version:

Code: Select all

set global variable: name = 'NMCE.pirates.check' value=[TRUE]

= wait randomly from 2000 to 3000 ms

$sectors = [PLAYERSHIP]-> find all sectors within 100 jumps: Only known sectors=[FALSE]

...
...
...
All work fine now !

Post Reply

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