Tutorial : Create a custom menu and Custom Interface Key (WIP)

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

User avatar
Knossos
Posts: 56
Joined: Tue, 1. Jun 04, 19:47
x4

Post by Knossos » Wed, 29. Apr 09, 15:34

Thank you very much for the tutorial.

Just created my first menu system.
Android Software Engineer
Try my hands-free notification reader for your car.

tank29
Posts: 16
Joined: Sat, 23. Jul 05, 16:07
x2

Post by tank29 » Fri, 29. May 09, 06:01

I have a quick question about the xml file. I have been trying to create my own simple version of LV's menu to start off with, but it seems that the game won't recognize the xml file. I'm basing this on the fact that I cannot see the command in the list of commands when I'm working on my setup script.

The file name is 8829-L044.xml (I am assuming this is the new format for xml files; the MSCI handbook and Cycrow's tutorials reference a nn####.xml format). Here are its contents:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?> 
<language id="44"> 



<page id="2008" title="Script Object Commands" descr="">
 <t id="1309">MY_FIRST_MENU</t>
</page>

<page id="2010" title="Script Cmd Names" descr=""> 
 <t id="1309">My First Menu</t>
 </page> 

<page id="2011" title="Script Cmd Shorts" descr=""> 
 <t id="1309">MFM</t>
 </page> 
 
<page descr='' id='8829' title='MyFirstMenu'>

<t id="1">This is the main menu Header</t>
<t id="2">Hello, hopefully this is the sub-header</t>
<t id="3">Menu Option 1</t>
<t id="4">Hello World</t>
</page> 
 

</language>
Can anyone see something that stands out as being wrong? I cannot get MY_FIRST_MENU to show up. Is the number 8829 reserved for something (seems pretty improbable)? I thought that 7000-9000 for the text file id were ok.

Thanks for the help!

tank29
Posts: 16
Joined: Sat, 23. Jul 05, 16:07
x2

Post by tank29 » Fri, 29. May 09, 06:44

Ok, well things are working when I label the xml file 448829.xml. Can someone explain why LV's file nomenclature works for his, but not mine?

User avatar
XDrake
Posts: 133
Joined: Wed, 29. Oct 08, 18:48
x3tc

Post by XDrake » Fri, 29. May 09, 16:56

tank29 wrote:Ok, well things are working when I label the xml file 448829.xml. Can someone explain why LV's file nomenclature works for his, but not mine?
You have to name the T file like '8829-L044.xml'.

The first part is the page number.

The L044 if for the language type.

Also I saw in the post before:

Code: Select all

<page descr='' id='8829' title='MyFirstMenu'> 
You have the descr= before the page id, The page id will come first. it should like:

Code: Select all

<page id='8829' title='MyFirstMenu' descr=""> 
When you make changes to the script, you must reinitialize the scritpt editor. It will run the old script in favor of the new one until you do or load a save file.
XDrake
-------------------------------------------------------
NECORE Inc.

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

Post by LV » Fri, 29. May 09, 17:40

upload your work

8829 is not used that i know of but i did request that 8800-50 were left to cater for my imperial needs, that said i have not used 8829 yet so you can run with it
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

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

Post by Cycrow » Fri, 29. May 09, 18:57

tank29 wrote:I have a quick question about the xml file. I have been trying to create my own simple version of LV's menu to start off with, but it seems that the game won't recognize the xml file. I'm basing this on the fact that I cannot see the command in the list of commands when I'm working on my setup script.

The file name is 8829-L044.xml (I am assuming this is the new format for xml files; the MSCI handbook and Cycrow's tutorials reference a nn####.xml format). Here are its contents:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?> 
<language id="44"> 



<page id="2008" title="Script Object Commands" descr="">
 <t id="1309">MY_FIRST_MENU</t>
</page>

<page id="2010" title="Script Cmd Names" descr=""> 
 <t id="1309">My First Menu</t>
 </page> 

<page id="2011" title="Script Cmd Shorts" descr=""> 
 <t id="1309">MFM</t>
 </page> 
 
<page descr='' id='8829' title='MyFirstMenu'>

<t id="1">This is the main menu Header</t>
<t id="2">Hello, hopefully this is the sub-header</t>
<t id="3">Menu Option 1</t>
<t id="4">Hello World</t>
</page> 
 

</language>
Can anyone see something that stands out as being wrong? I cannot get MY_FIRST_MENU to show up. Is the number 8829 reserved for something (seems pretty improbable)? I thought that 7000-9000 for the text file id were ok.

Thanks for the help!
MY_FIRST_MENU will be the new of the command within the script editor, i assume thats where you are looking for it ?

what do you have in the commands list, do you have any readtexts or anything ?

it could be serveral things, you might not have registered the command correctly, or not loaded the text file correctly. Without seeing the rest of the scripts it would be impossible to tell where your problem lies

tank29
Posts: 16
Joined: Sat, 23. Jul 05, 16:07
x2

Post by tank29 » Fri, 29. May 09, 19:31

Thanks for the responses. As soon as I get to my personal computer, I'll upload everything (the setup and main script).

But in the meantime, the new xml file nomenclature is <text id>-<language format>.xml. Is that correct? That seems to be what XDrake implied, but I just want to be clear on this.

tank29
Posts: 16
Joined: Sat, 23. Jul 05, 16:07
x2

Post by tank29 » Sat, 30. May 09, 01:28

Ok here is the setup script (setup.menu.test):

Code: Select all

load text: id=8829
add ship custom command: id=1309
set script command upgrade: command= MY_FIRST_MENU upgrade=[TRUE]
global script map: set: key= MY_FIRST_MENU, class= Moveable Ship, race= Player, script= a.menu.test.main, prio=0
return null
Here is the main script (a.menu.test.main)

Code: Select all

$text = sprintf: pageid= 8829 textid= 2, null, nulll, null, null, null
$menu  = create custom menu array: heading= $text
$text = sprintf: pageid= 8829 textid= 3, null, nulll, null, null, null
add custom menu item to array $menu : text= $text returnvalue= $input1
$text = sprintf: pageid= 8829 textid= 4, null, nulll, null, null, null
add custom menu item to array $menu : text= $text returnvalue= $input2
$text = sprintf: pageid= 8829 textid= 1, null, nulll, null, null, null
$return = open custom menu: title= $menu description= $text option array= $menu
I'll work on getting the actual files uploaded in a bit

User avatar
XDrake
Posts: 133
Joined: Wed, 29. Oct 08, 18:48
x3tc

Post by XDrake » Sat, 30. May 09, 07:47

tank29 wrote:Ok here is the setup script (setup.menu.test):

Code: Select all

$text = sprintf: pageid= 8829 textid= 2, null, nulll, null, null, null
$menu  = create custom menu array: heading= $text
$text = sprintf: pageid= 8829 textid= 3, null, nulll, null, null, null
add custom menu item to array $menu : text= $text returnvalue= $input1
$text = sprintf: pageid= 8829 textid= 4, null, nulll, null, null, null
add custom menu item to array $menu : text= $text returnvalue= $input2
$text = sprintf: pageid= 8829 textid= 1, null, nulll, null, null, null
$return = open custom menu: title= $menu description= $text option array= $menu
What I can see is that you are using the spritnf. This is used to format the text that is read.

You may want to try using:

Code: Select all

$text = read text: page 8829 id=#
With the spritf you have the options of adding color and other formating stuff..

This links may help some on what you can do.

http://forum.egosoft.com/viewtopic.php? ... &start=105

http://www.cplusplus.com/reference/clib ... rintf.html
XDrake
-------------------------------------------------------
NECORE Inc.

tank29
Posts: 16
Joined: Sat, 23. Jul 05, 16:07
x2

Post by tank29 » Sat, 30. May 09, 16:24

I'll check out the forum link thanks. And thanks for the tip on the more simple read command. What's really frustrating about this is that I used LV's code as the core and just made some changes to it. What I going to do today is make the changes one at a time and see what happens.

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

Post by Cycrow » Sat, 30. May 09, 17:28

sprintf and read text is actually no different at all. They both do the same formating. The only difference between the 2 commands, is that sprintf will replace the 5 arguments in your text, the first 5 %s that it reads, with the 5 values given in the command.

if you text doesn't have any %s or you set it all the null, then the 2 commands are identical

althou, the simple read text one is usually easier to read


u say MY_FIRST_MENU didn't show up, what exactly did u mean by that, where doesn't it show it ?

its obviously been added, and the text is working, as you have selected it in your setup script

tank29
Posts: 16
Joined: Sat, 23. Jul 05, 16:07
x2

Post by tank29 » Sat, 30. May 09, 18:06

Well, I'm not sure what the issue was earlier, but I started completely from scratch and things are working now. Thanks everyone for the help. I'm guessing there was just some sort of syntax error somewhere (this is my first time working with xml).

For the curious, the problem I was having earlier is that when I was trying to select the command MY_FIRST_MENU in the set script command upgrade it wasn't listed. I was pretty wiped out from work yesterday when I transcribed the text of the scripts to the forums, so MY_FIRST_MENU being in those two commands was likely wishful thinking. :oops:


Now that that's fixed, I am wondering if there is an explanation somewhere of the menu scripting commands:
  • add custom menu item to array
    add custom menu heading to array
    add custom menu info line to array
    create custom menu array
    create custom menu array: heading =
    create custom menu array, info lines=
I'm specifically curious about two things: 1) How do you get text in the very top of the menu (to the immediate left of the buttons) and 2) how do you separate the menu items into different sections?

Example of #2:

Section 1 Heading (non-selectable)
Menu Option 1 (selectable)
Menu Option 2 (selectable)
(empty line)
Section 2 Heading (non-selectable)
Menu Option 3 (selectable)

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

Post by Cycrow » Sat, 30. May 09, 18:49

the problem was most likly that u never ran the script first. You see, before the command appears, you need to run the command to add it.

so the next time you tryed from scratch, you most likly had it run first, ie from the previous attempt, so it was for you to use.

as for the menu commands, they do pretty much what they say. Menus are basically arrays of all the entries. The 3 add commands add the items into the menu array.

The create commands create the initial menu array. the create array: heading, is the same as doing, create menu, followed by add heading, same with the infoline.

for what you want, you need to add headings.

Code: Select all

$menu = create custom menu array: heading = "section 1 heading"
add custom menu item to array: $menu, "Menu Option 1"
add custom menu item to array: $menu, "Menu Option 2"
add custom menu heading to arrya: $menu, "Section 2 heading"
add custom menu item to array: $menu, "Menu Option 3"
you cant really add an empty line

tank29
Posts: 16
Joined: Sat, 23. Jul 05, 16:07
x2

Post by tank29 » Sat, 30. May 09, 20:25

Ahh, thanks for the clarification on the menu. I had read many people say that a menu is just an array, but it didn't really click until just now. The add menu heading command is just a different type of data value in the array, as opposed to the command that creates a selectable option (again, just a different type of data in the array).

Thanks for the help!

One last question: When I select either my custom menu or LV's, autopilot tries to start (both from a mouse click selection of the menu or enter key). Has anyone come across this before?

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

Post by Cycrow » Tue, 30. Jun 09, 02:20

where are you running the menu from, i assume from the command console ?

if you set the command on the ship, then when the script is run, it will enable the autopilot. If all your doing is running a menu, there are several things you can do.

the first is to not set the command name for the script then just display the menu.

or you can set up a preload. The preload can then display the menu, then you simply dont return anything, and the command console will never actually be run. Allowing you to have a menu do what ever you want without preventing existing commands on the ship

User avatar
Litcube
Posts: 4254
Joined: Fri, 20. Oct 06, 19:02
xr

Post by Litcube » Tue, 25. Aug 09, 03:35

Hey dudes!

What would you recommend for a menu that is designed only to show information? For example, say you have a main menu with a bunch of options. Clicking on one of those options pops up another menu that's really only supposed to display information until you hit esc. What would you dudes do for this?

- Infolines aren't long enough for a lot of data (and scrolling only works with the mouse)

- A list of menu items are selectable, and the info isn't really supposed to be.

Any ideas?

testmod
Posts: 71
Joined: Fri, 13. Mar 09, 04:59
x3tc

Post by testmod » Sun, 13. Dec 09, 04:18

If i want to bind a script to a hotkey, is this the right tutorial to follow?

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

Post by LV » Sun, 13. Dec 09, 10:35

set the hotkey

Code: Select all

019   |$key = get global variable: name='lv.dai.hk'
020   |if $key == null
021   ||$txt = sprintf: pageid=8840 textid=1, null, null, null, null, null
022   ||$id =  register hotkey $txt to call script 'plugin.lv.drone.ai.interface'
023   ||set global variable: name='lv.dai.hk' value=$id
024   |end
remove the hotkey

Code: Select all

008   |$key = get global variable: name='lv.dai.hk'
009   |if $key != null
010   ||unregister hotkey $key
011   ||set global variable: name='lv.dai.hk' value=null
012   |end
I'm calling the hotkey text from a tfile here but you can just type if in if you want.
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

testmod
Posts: 71
Joined: Fri, 13. Mar 09, 04:59
x3tc

Post by testmod » Sun, 13. Dec 09, 18:47

thanks LV!

XenoWish
Posts: 6
Joined: Sat, 13. Nov 04, 11:41
x3

Post by XenoWish » Sun, 4. Apr 10, 17:02

hey guys. i keep getting a readtext2010-558 as my menu title in special commands. as far as i can tell everything is correct but i guess i must be missing something. first attempt at a menu here so um yeah... also. after the script is run to open the menu the first time it just pops up on me when im not even in the area to select the menu option. or even out of nowhere every few seconds when i have no menus open. anything you guys can think imm messin up here. i installed the tutorial scripts and pretty much just made a copy of them and am editing them and removing the unwanted menu options although i havent gotten that far yet so ptretty much its almost a ful copy of the tutorial scripts under different names except for some minor editing to get them to run for testing.

Post Reply

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