X3 Tutorial : Sending an Incoming Question

The place to discuss scripting and game modifications for X³: Reunion.

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

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

Post by Cycrow » Mon, 12. Dec 05, 23:22

if i have something like

Code: Select all

[center]
some text here
[select value="1"]1[/Select]\n
[select value="2"]2[/Select]\n
[select value="3"]3[/Select]\n
[select value="4"]4[/Select]\n
[select value="5"]5[/Select]\n
[/center]
then i only get 4 options but if i do

Code: Select all

[center]
some text here
[select value="1"]1[/Select]\n
[select value="2"]2[/Select]\n
[select value="3"]3[/Select]\n
[select value="4"]4[/Select]\n[/center]
[select value="5"]5[/Select]\n
then i get all five, the same as if i remove the center tags all together, i get all 5

and if i have any text underneth, that doesn't show up either if the 5th option is centers, but it does otherwise

User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot » Fri, 16. Dec 05, 22:46

Dont know if this is me ..
but I cant pass a ship to the callback script and still use this object
(seems the object has become a string or so)

anyway .. because I couldnt get this done ..
I figured I had to pass something to identify the ship ..
so I did it like this ..
(the way I did it in this example shows how to send an incoming Q. than have the ship wait for your answer than carry on ........)

Code: Select all

005   $Ret = [THIS] -> get ID code
006   set global variable: name=$Ret value=[THIS]
007   $Dock = sprintf: pageid=8601 textid=8, $Name, [THIS], [SECTOR], $Ret, $Ret
008   send incoming question $Dock to player: callback='RS.Secur.Callback'
009   $Dock = null
010   while not $Dock
011    $Dock = [THIS] -> get local variable: name='rs.security.docking'
012 @  = wait 2000 ms
013   end
014   skip if $Dock == 1
015    $Dock = null
016   [THIS] -> set local variable: name='rs.security.docking' value=null
and the callback script

Code: Select all

Arguments
1: ID.Code , Var/String , 'ID Code' 
2: Callback , Var/String , 'Callback' 
Source Text

001   $Leader = get global variable: name=$ID.Code
002   skip if $Leader -> exists
003    goto label End
004   if $Callback == 'yes'
005    $Leader -> set local variable: name='rs.security.docking' value=1
006   else
007    $Leader -> set local variable: name='rs.security.docking' value=2
008   end
009   End:
010   set global variable: name=$ID.Code value=null
011   return null

where you can see the ID-code off the ship gets used as name for a global var with the ship itself stored..

now by passing the ID-code and looking for a global var with that name returns your ship without having to loop thru the entire universe..

tought this might be helpfull..


G

User avatar
RJV
Posts: 2099
Joined: Mon, 29. Mar 04, 09:45
x3tc

Anybody get the 'passing array' thing to work???

Post by RJV » Wed, 8. Mar 06, 11:41

Just been having a go at this whole Incoming question thing, and it works quite well.

Sort of.

Sending the question, putting the buttons in, activating the callback script, all fine and dandy and looks great.

But I return to the issues earlier - passing arrays using the value string. Has anyone done it successfully? I spent a considerable amount of head-scratching, cussing and general frustration time trying to get it to work, to no avail. Had to resort to setting a global variable before the question, then reading it afterwards, which works quite nicely, but it still narks me that I couldn't get the prescribed method to work.

Very briefly - the problem I was getting was that if I passed an array as the first %s parameter when setting up the button, when I checked the value of that variable in the reply script I was getting the following value ARRAY(4) Now, what I was passing was an array containing 5 elements (each of which was another array of 4 elements).

I read and re-read the stuff earlier until it actually seemed more complicated by the time I finished then when I'd started :roll: Particularly the bit about curly braces, which I would have tried if I knew how to get a curly brace into a script (anyone?).

So, after getting that off my chest - has anyone managed to successfully pass an array using the methods above, and if so, HOW?!?!?!?

Cheers, (and thanks for listening :) )

Rob.

User avatar
Kailric
Posts: 985
Joined: Sun, 7. Dec 03, 05:15
x3

strange bug of some sort?

Post by Kailric » Fri, 14. Jul 06, 06:51

While working with this command I encountered something strange....

I was passing 3 values through a question: a number, a ship, and a station. I converted the ship and station to serials as well.

They all passed through just fine has when I told the script to print them my log showed just that.

Now, I tried to run a script on the ship such as this:

Code: Select all

043 @ skip if $ship -> call script 'TK.cmd.list' :  check only=$station  ship=$ship
044    return null
The problem is the script will not run the script 'TK.cmd.list' at all when done like this. I had to change the line to this:

Code: Select all

043 @ skip if [THIS] -> call script 'TK.cmd.list' :  check only=$station  ship=$ship
044    return null
The script will then run, but when I tell the 'TK.cmd.list' script to run a script on $station.. same thing happens and I get an infinite loop detection error.


Funny thing is all I have to do to get the first code to work is in an earlier script set a global varable as this, where [THIS] is the ship:

Code: Select all

004   set global variable: name=[THIS] value=[THIS]

And then in my script add this line before the code:

Code: Select all

042   $ship = get global variable: name=$ship
043 @ skip if $ship -> call script 'TK.cmd.list' :  check only=$station  ship=$ship
044    return null
Done that way the script will work. Of course I have to do the same thing for the station. But why is that?

Can someone tell me what is happening here?


EDIT:
RJV wrote: So, after getting that off my chest - has anyone managed to successfully pass an array using the methods above, and if so, HOW?!?!?!?
Rob.
This queston is several months old but if someone else looks here:

I do believe I passed an array. Try putting the { } in your t file such as [select value= '{ %s,%s,%s}']Push Here[/select]. I done that and in one test it worked. But here is something funny happening here that I don't understand... yet.
"Try not. Do or do not, there is no try."-Yoda

"[Its] time for the human race to enter the solar system"-Dan Quayle

User avatar
Moonraven
Posts: 968
Joined: Wed, 27. Aug 03, 11:13
x3

Post by Moonraven » Sun, 17. Sep 06, 11:44

Ok, this thread is a little old, but i hope my answer will help you out :)

So..here is how to deal with Arrays:


First...a look a the t-file-entry(s):

Code: Select all

      <page id="8888">
              <t id="100">Some text\n\n
                                [select value="YES,{%s,%s,%s}"]YES[/select]\n\n
                                [select value="NO,{%s,%s}]NO[/select]
              </t>
      </page>
ok..you see the brace around the %s. this marks it as an array.

I use only 5 "%s" because sprintf can't do more at one time. If you need
more, than you have to split the message in multiple parts and multiple
sprintf's.

ok....now we send the message...just simple:

Code: Select all

      $message = sprintf: pageid=8888 textid=100,"Y1","Y2","Y3","N1","N2"
      send incomint question $message to player: callback="<your callbacksript>"
Ok..this was the simple part !

Now...the callback-script:

Code: Select all

Script <your scriptname>
Version: 0
for Script Engine Version: 32
Description
Description
Arguments

    * 1: val , Var/String , 'val'
    * 2: arr , Value , 'arr'

Source Text

001   $count =  size of array $arr
002   $v1 = $arr[0]
003   $v2 = $arr[1]
004   $v3 = $arr[2]
005   $mess = sprintf: fmt='Answer  %s  Count %s Values %s,%s,%s', $val, $count, $v1, $v2, $v3
006   send incoming message $mess to player: display it=[TRUE]
007   return null
Ok...a little explain:

As you can see the second parameter is simple a value. This is because
there is no parametertype "VAR/Array". Each script that uses an array as
parameter, has to use the type "value" for this.

Also, it is important, the position of the parameter:

if you have defined the array as 3. value in the t-file, it has to be the
3. parameter of the callback-script !

Well i hope this helps you :)
Gruß Moonraven
Wer lesen kann, ist ganz klar im Vorteil.
[ external image ]

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

Post by s9ilent » Sun, 15. Apr 07, 04:13

After lots of trial and error, there does not appear to be a way to input more arguments, when your half way through a script/question chain


So... LOTS of mini menus will be required...
But this way is ineffecient, as I have to eventually create a button for each choice (keeping a cancel button spare too)
So... Ill either have to use many many manually written mini menu's
showing upto 4 options at a time with a next button, or more likely 3 options a cancel and a next button


Or... variables from an array using %s for the buttons name and value, meaning 2 options at a time, leave 3 buttons spare, one for next pre and cancel


But I'm trying to present a total of maybe 10-20 options... man this is going to take ages...

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

Post by Cycrow » Sun, 15. Apr 07, 18:04

what do you mean by import more arguments ?

i dont c the problem with having 10 options

B-O'F
Posts: 724
Joined: Sat, 21. Feb 04, 02:15
x3tc

Post by B-O'F » Sun, 15. Apr 07, 21:04

Hi s9ilent,

As I said in an earlier post - look at my scripts in the Remote Docked Freight Transfer. I have easily had 70+ entries in an incoming question - bof.xfer.operate.picklist which is set up by bof.xfer.upgrade.pick or bof.xfer.select.to ship.

It is just that you can only pass 10 parameters (including any elements in an array) - so don't use them. Use a global array instead, much easier and more effective - which is why I pass all the required data in the global array $data, which points to any required arrays (such as list of wares, or list of docked ships). The callback scripts are straitforward.

If you want to see if there is a limit, dock a hundred or more ships, and transfer a single energy cell - see what the 'Select To ship' pick list looks like -- a bit long.......

My scripts are pretty well documented, so you should be able to read them fairly easily. At the bottom of bof.xfer.main there is a listing showing the use of the array $data.

The main purpose of the documentation is for me to understand why I did things that way - important when you go back to a script after a few months or years.... (or even seconds)....

Once a list has been built and a selection has been made, you can rebuild the list from scratch and change the items shown ready for the next selection. Look at bof.xfer.upgrade.pick for an example.

Remember that selection lists are not static - once a selection has been made the screen is wiped and another list (or the original) can be shown for a second pick. bof.xfer.upgrade.pick just sets/resets an indicator to show if a ware has been selected - but it could be a new list, or an updated list.

There is no way to input arguments using the standard argument inputs - you have to get that information first, which is not always convenient. You can build a numeric entry selection using incoming question - just like a calculator, with a currently entered number, enter, and clear - I have done it.. but as you can only have one entry per line it looks naff...


Think carefully about what information you need the player to enter, and try to get as much as possible in the beginning. If their choice requires a standard type input - then you will have to use two command slots. For a good example of this see siath70's "Station Administrator" - this changes the required input from the player depending on the selection made in an incoming question. One command slot has the incoming questions, the other has the required input - you do have to go from your log back to the input command - a slight drawback.

Egosoft have not yet given us a good way of getting input from the player - incoming questions are a step in the right direction, but a very small step.

There are many ways to solve problems, but first define the problem..

Boron - Ol Fh'art
Public Service announcement

Growing old is not a disease - it is a delayed symptom of birth trauma.

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

Post by s9ilent » Sun, 15. Apr 07, 23:32

I had ... the most AWESOME idea ever, To use virtually unlimited %s 'es in your question
use sprintf, multiple times!
(Obviously one of the time it will call a template page id whos sole contents are "%s %s %s %s %s" )

Eg You first sprint might be...
m1 = sprint 1 2 3 4 5
m2 = sprint 6 7 8 9 10

m3 = sprint m1 m2




And after looking at your scripts, I see you thought of that too. Made me life easy for me. Cheers

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

Post by Cycrow » Mon, 16. Apr 07, 00:42

u could look at some of my scripts, i create questions by joining strings together, ie

Code: Select all

<t id="1">[select value="%s,%s"]%s[/select]\n</t>
<t id="2">Question\n\n%s</t>

Code: Select all

$question = sprintf: pageid = $page.id, id = 1, 1, $varible, Question 1
$full = $question
$question = sprintf: pageid = $page.id, id = 1, 2, $varible, Question 2
$full = $full + $question
$question = sprintf: pageid = $page.id, id = 1, 3, $varible, Question 3
$full = $full + $question
$full = sprintf: pageid = $page.id, id = 2, $full

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

Post by s9ilent » Mon, 16. Apr 07, 03:45

Thanks Cycrow, I had just worked that out in my last post (After looking at B O F's scripts, Nice uncapitolize everything script by the way). But... now the game crashes... I think I must have an infite loop somewhere...
Loop found, Loop being stubborn....Still being stubborn :x. Loop dead gone and never existed!!!


:( The game doesn't support using Multiple [text] thingies in a single message. It will only load the first one.
Why is making sets of colums so difficult :S

B-O'F
Posts: 724
Joined: Sat, 21. Feb 04, 02:15
x3tc

Post by B-O'F » Mon, 16. Apr 07, 11:01

Hi s9ilent,

Incoming questions only supports one button per line.

For information on displaying (but not selecting) data in columns see "Chem Report System for Dockware Manager" here

Boron - Ol Fh'art
Public Service announcement

Growing old is not a disease - it is a delayed symptom of birth trauma.

Post Reply

Return to “X³: Reunion - Scripts and Modding”