[TUTORIAL] Creating menus + two library scripts
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
[TUTORIAL] Creating menus + two library scripts
Creating beautiful menus in X³:Terran Conflict
Since patch 2.5 is finally out, I decided to release a little tutorial on menus I wrote some time ago. It will especially describe the new menu commands coming with patch 2.5.
To fully understand this tutorial you should at least know how arrays work, because they are the basis for menus.
Other than that, there is not much to know.
-----------------------------------------------
Download: Tutorial - Creating menus (85 Kbyte)
Alternative link: Creating beautiful menus in X3: Terran Conflict (Egosoft X3 wiki)
-----------------------------------------------
If requested, I might add pictures to the tutorial, but I hope it is understandable anyways.
-----------------------------------------------
Library scripts
lib.scrat.format
A library for formatting your menus more easily.
lib.scrat.expand
A library for adding expandable menu selections to your script.
Examle animation:
[ external image ]
Both are explained and available here.
Alternative link:
Creating menus + two library scripts (Egosoft X3 wiki)
Please report, ask questions and give feedback.
-----------------------------------------------
For any comment, idea, mistake feel free to post in this thread.
Greetings,
ScRaT
Since patch 2.5 is finally out, I decided to release a little tutorial on menus I wrote some time ago. It will especially describe the new menu commands coming with patch 2.5.
To fully understand this tutorial you should at least know how arrays work, because they are the basis for menus.
Other than that, there is not much to know.
-----------------------------------------------
Download: Tutorial - Creating menus (85 Kbyte)
Alternative link: Creating beautiful menus in X3: Terran Conflict (Egosoft X3 wiki)
-----------------------------------------------
If requested, I might add pictures to the tutorial, but I hope it is understandable anyways.
-----------------------------------------------
Library scripts
lib.scrat.format
A library for formatting your menus more easily.
lib.scrat.expand
A library for adding expandable menu selections to your script.
Examle animation:
[ external image ]
Both are explained and available here.
Alternative link:
Creating menus + two library scripts (Egosoft X3 wiki)
Please report, ask questions and give feedback.
-----------------------------------------------
For any comment, idea, mistake feel free to post in this thread.
Greetings,
ScRaT
Last edited by ScRaT_GER on Sat, 3. Mar 12, 16:54, edited 5 times in total.
one thing u didn't really mention about columns.
using a - value will right align based on the number, so as you said, -1 will be at the end. but u can use other numbers, -10 would move the text 10 pixels to the left, so there will be a 10 pixel gap between the end of the text and the edge of the menu
so this allows you to create column both ways, -1, -100, -200, could create 3 columns, all right aligned
and for value selections, it is possible to have the selections work without selecting an option from the menu, ie, if you press escape u get the return value of -1, without any of the changed value selections, but it is possible to get it working like that, by creating the selections manually and storing the array. As the menus will directly manipulate that array to change the values, u can then check it after to get whats changed, even when esc was pressed to close the menu.
1.60 of my cheats scripts does this for anyone who wants an example of it.
also looking at the board ship preload will help with column, as that uses custom columns as well
using a - value will right align based on the number, so as you said, -1 will be at the end. but u can use other numbers, -10 would move the text 10 pixels to the left, so there will be a 10 pixel gap between the end of the text and the edge of the menu
so this allows you to create column both ways, -1, -100, -200, could create 3 columns, all right aligned
and for value selections, it is possible to have the selections work without selecting an option from the menu, ie, if you press escape u get the return value of -1, without any of the changed value selections, but it is possible to get it working like that, by creating the selections manually and storing the array. As the menus will directly manipulate that array to change the values, u can then check it after to get whats changed, even when esc was pressed to close the menu.
1.60 of my cheats scripts does this for anyone who wants an example of it.
also looking at the board ship preload will help with column, as that uses custom columns as well
You're right. I'll mention that.so this allows you to create column both ways, -1, -100, -200, could create 3 columns, all right aligned
I mentioned that.it is possible to have the selections work without selecting an option from the menu, ie, if you press escape u get the return value of -1
Which array will they directly manipulate (in the following code example)?As the menus will directly manipulate that array to change the values, u can then check it after to get whats changed, even when esc was pressed to close the menu.
Code: Select all
add value selection to menu: $menu, text=$text, value array=$array, default=$id, return id=$dummy
ScRaT
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
Hi ScRat_GER,
Great guide which is helping me convert my menus, thanks
However I'm having an issue with the game locking up if I try to make my menus dynamic.
Do you whats wrong with the below:
'plugin.FDN4.Node.Menu.Global' is called as a task by the menu and it works out the docks current used storage level:
This is the menu (segment of it):
There is more to the menu but the above is what I've done to try and make the stock level dynamic.
The lockup happens just after the '= wait 1000 ms'
Any pointer would be great.
Thanks
LA
Great guide which is helping me convert my menus, thanks
However I'm having an issue with the game locking up if I try to make my menus dynamic.
Do you whats wrong with the below:
'plugin.FDN4.Node.Menu.Global' is called as a task by the menu and it works out the docks current used storage level:
Code: Select all
while $menu.check == [TRUE]
$infoHeader = array alloc: size=0
append 1 to array $infoHeader
$text = read text: page=$PageID id=122
append $text to array $infoHeader
append 120 to array $infoHeader
$curr = $node->get total volume in cargo bay
$curr = convert number $curr to string
$max = convert number $max to string
$storage = '(' + $curr + ')'
append $storage to array $infoHeader
$current = sprintf: pageid=$PageID textid=2030, $node, null, null, null, null
set global variable: name=$current value=$infoHeader
= wait 1000 ms
$menu.check = $node->get local variable: name=$menu
end
Code: Select all
$task = $node->get next available task: starting=$PageID
$node->start task $task with script 'plugin.FDN4.Node.Menu.Global' and prio 100: arg1=$node arg2=null arg3=null arg4=null arg5=null
while [TRUE]
$text = read text: page=$PageID id=104
$menu = create custom menu array: heading=$text
$text = read text: page=$PageID id=909
add custom menu heading to array $menu: title=$text
$storage.check = sprintf: pageid=$PageID textid=2030, $node, null, null, null, null
$storage = get global variable: name=$storage.check
add custom menu item to array $menu: text=$storage returnvalue=null
$text = read text: page=$PageID id=104
$desc = sprintf: pageid=$PageID textid=9000, $name, null, null, null, null
$ret = open custom menu: title=$text description=$desc option array=$menu
skip if not is datatyp[ $ret ] == {DATATYP_ARRAY}
$ret = $ret[0]
if $ret == -1
goto label exit
else
= [THIS]->call script 'plugin.FDN4.Node.Menu.Action' : node=$node action=$ret
end
end
The lockup happens just after the '= wait 1000 ms'
Any pointer would be great.
Thanks
LA
i assume what your trying to do is have the infolines change while the menu is still open ?
your script wont accomplish that however.
when you run the menu script, it will get the global varible ones, $storage, and display your menu, but the script will wait until you close the menu, by escape, or selecting an option, which means it will only update when a selection is made and the menu will close and reopen.
is that how you wanted it to work ?
what kind of lockup is it, does the game just completly stop ?
and is it always at the same point ?
what if you remove the the line below it, does it still lock up ?
also, you dont seem to have $menu defined, is that set somewhere else?
your script wont accomplish that however.
when you run the menu script, it will get the global varible ones, $storage, and display your menu, but the script will wait until you close the menu, by escape, or selecting an option, which means it will only update when a selection is made and the menu will close and reopen.
is that how you wanted it to work ?
what kind of lockup is it, does the game just completly stop ?
and is it always at the same point ?
what if you remove the the line below it, does it still lock up ?
also, you dont seem to have $menu defined, is that set somewhere else?
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
Hi Cycrow,Cycrow wrote:i assume what your trying to do is have the infolines change while the menu is still open ?
your script wont accomplish that however.
when you run the menu script, it will get the global varible ones, $storage, and display your menu, but the script will wait until you close the menu, by escape, or selecting an option, which means it will only update when a selection is made and the menu will close and reopen.
is that how you wanted it to work ?
what kind of lockup is it, does the game just completly stop ?
and is it always at the same point ?
what if you remove the the line below it, does it still lock up ?
also, you dont seem to have $menu defined, is that set somewhere else?
Thanks for the quick reply.
The menu works fine normally, if I don't try and make the value update dynamically.
From ScRat_GER guide I was hoping the get the value to update every second like an in-game menu.
The lockup happens when the 'plugin.FDN4.Node.Menu.Global' loops after its first call.
If I remove the while statement from 'plugin.FDN4.Node.Menu.Global' so it only runs once there is no lockup.
Looks like I've mis-understood the guide.
On a linked issue, I can get the new 2.5 columns working fine with 'add custom menu item to array :<Array>: text=$array returnvalue=null' but nothing shows if I use the 'add custom menu info line to array:<Array>: text=$array'?
Thanks
LA
you can technically make the menu update every seconds, but you need to manipulate the menu array directly.
also, after your infolines, trying adding a blank one below, there seems to be a problem with it counting infolines when using a text array
just set the blank one to use a text of ' '
ie, a single space.
for the dynamic update, u'll need to use the same array, not keep creating a new one
could do something like
then in your other, you will have a second argument that will be this array
also, you never said what the $menu is defined as ? i mean the one in plugin.FDN4.Node.Menu.Global
also, after your infolines, trying adding a blank one below, there seems to be a problem with it counting infolines when using a text array
just set the blank one to use a text of ' '
ie, a single space.
for the dynamic update, u'll need to use the same array, not keep creating a new one
could do something like
Code: Select all
$storageInfo = create array with arguments, 1, $text1, 120, $text2
$task = $node->get next available task: starting=$PageID
$node->start task $task with script 'plugin.FDN4.Node.Menu.Global' and prio 100: arg1=$node arg2=$storageInfo arg3=null arg4=null arg5=null
while [TRUE]
$text = read text: page=$PageID id=104
$menu = create custom menu array: heading=$text
$text = read text: page=$PageID id=909
add custom menu heading to array $menu: title=$text
add custom menu item to array $menu: text=$storageInfo returnvalue=null
Code: Select all
while $node -> get local variable: name=$menu
$curr = $node->get total volume in cargo bay
$curr = convert number $curr to string
$max = convert number $max to string
$storage = '(' + $curr + ')'
$storeageInfo[3] = $storage
= wait 1000 ms
end
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
Cheers Cycrow, time to have another play, which is half the funCycrow wrote:you can technically make the menu update every seconds, but you need to manipulate the menu array directly.
also, after your infolines, trying adding a blank one below, there seems to be a problem with it counting infolines when using a text array
just set the blank one to use a text of ' '
ie, a single space.
for the dynamic update, u'll need to use the same array, not keep creating a new one
could do something like
then in your other, you will have a second argument that will be this arrayCode: Select all
$storageInfo = create array with arguments, 1, $text1, 120, $text2 $task = $node->get next available task: starting=$PageID $node->start task $task with script 'plugin.FDN4.Node.Menu.Global' and prio 100: arg1=$node arg2=$storageInfo arg3=null arg4=null arg5=null while [TRUE] $text = read text: page=$PageID id=104 $menu = create custom menu array: heading=$text $text = read text: page=$PageID id=909 add custom menu heading to array $menu: title=$text add custom menu item to array $menu: text=$storageInfo returnvalue=null
also, you never said what the $menu is defined as ? i mean the one in plugin.FDN4.Node.Menu.GlobalCode: Select all
while $node -> get local variable: name=$menu $curr = $node->get total volume in cargo bay $curr = convert number $curr to string $max = convert number $max to string $storage = '(' + $curr + ')' $storeageInfo[3] = $storage = wait 1000 ms end
LA
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
I’ve not seen this issue/consideration posted (although I’m sure it‘s been mentioned) so I thought it may help others.
When using the new ‘create new array, arguments’ command for menu value selection, if you change the selection then call another command, say one that open another menu, or uses an input box without first ensuring the selection change is written, your update will be lost.
An example would be Cycrow excellent cheat scripts (which I’ve used to learn how to write the new style menus), if you open the menu, change the unlimited insurance value, then use another command that calls another input (create ship or station) you will notice that the insurance value has reverted to is initial value. This is because the code which updates values based on the user selection is only called when the page is updated. You need to ensure its called if before you open another menu or input box from your initial menu.
I noticed this as the menus I’m building had the same issue:
The first example is a template I use based on Cycrow cheat menu:
I’ve added a new sub that is called when another update or command is called other than exit.
Like I’ve said, I’m sure it’s been mentioned but if your like me it helps to have examples. Hope it helps.
LA
When using the new ‘create new array, arguments’ command for menu value selection, if you change the selection then call another command, say one that open another menu, or uses an input box without first ensuring the selection change is written, your update will be lost.
An example would be Cycrow excellent cheat scripts (which I’ve used to learn how to write the new style menus), if you open the menu, change the unlimited insurance value, then use another command that calls another input (create ship or station) you will notice that the insurance value has reverted to is initial value. This is because the code which updates values based on the user selection is only called when the page is updated. You need to ensure its called if before you open another menu or input box from your initial menu.
I noticed this as the menus I’m building had the same issue:
The first example is a template I use based on Cycrow cheat menu:
Code: Select all
while [TRUE]
$menu = create custom menu array: heading='text goes here'
add custom menu heading to array $menu: title='text goes here'
'Your Menu items are built here'
$ret = open custom menu: title='text' description='text' option array=$menu
skip if not is datatyp[ $ret ] == {DATATYP_ARRAY}
$ret = $ret[0]
if $ret == -1
goto label exit
else
'Code to call other page or updates goes here'
end
end
exit:
if $aValues
$count = size of array $aValues
while $count
dec $count =
$a = $aValues[$count]
$wasOn = $aDefaults[$count]
gosub sub.DoValue
end
end
return null
sub.DoValue:
$id = $a[4]
$isOn = $a[3]
if $isOn != $wasOn
if $id == 'status'
if $wasOn == 1
'Code to update valube selection goes here'
end
end
endsub
return null
Code: Select all
while [TRUE]
$menu = create custom menu array: heading='text goes here'
add custom menu heading to array $menu: title='text goes here'
'Your Menu items are built here'
$ret = open custom menu: title='text' description='text' option array=$menu
skip if not is datatyp[ $ret ] == {DATATYP_ARRAY}
$ret = $ret[0]
if $ret == -1
goto label exit
else
gosub sub.load
'Code to call other page or updates goes here'
end
end
exit:
if $aValues
$count = size of array $aValues
while $count
dec $count =
$a = $aValues[$count]
$wasOn = $aDefaults[$count]
gosub sub.DoValue
end
end
return null
sub.load:
if $aValues
$count = size of array $aValues
while $count
dec $count =
$a = $aValues[$count]
$wasOn = $aDefaults[$count]
gosub sub.DoValue
end
end
endsub
sub.DoValue:
$id = $a[4]
$isOn = $a[3]
if $isOn != $wasOn
if $id == 'status'
if $wasOn == 1
'Code to update value selection goes here'
end
end
endsub
return null
LA
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
Hi Cycrow,
Thanks for your pointer with the dynamic menu update.
After a few hours testing I got it working, my initial code was close, it looked like the script which updates the array in the Global didn’t like working directly with objects.
So something like ‘$current = $node->get total amount of ware $ware in cargo bay’ would cause the game to freeze, however if I called another script to provide the value it works with no issue.
Steps I found that work:
Open script which updates the required values to global array (script1)
Open Menu (script 2)
Use a third script (script3) called by (script1) when you need to return a value from an object.
My FDN Nodes now have menus which dynamically update the storage used, just like in-game menus
The issue I have now is that the menu won’t show dynamic updates when the menu item which is global is referred from within a while loop, say you want to list wares and their amounts.
LA
Thanks for your pointer with the dynamic menu update.
After a few hours testing I got it working, my initial code was close, it looked like the script which updates the array in the Global didn’t like working directly with objects.
So something like ‘$current = $node->get total amount of ware $ware in cargo bay’ would cause the game to freeze, however if I called another script to provide the value it works with no issue.
Code: Select all
WORKS:
$a = array alloc: size=4
$a[0] = 1
$a[2] = 120
$aStorage = create new array, arguments=$a, [TRUE], null, null, null
$global = sprintf: pageid=$PageID textid=2041, $node, null, null, null, null
set global variable: name=$global value=$aStorage
while $active == 1
$curr = [THIS]->call script 'plugin.FDN4.Node.Menu.Values' : node=$node caller='curr'
$max = [THIS]->call script 'plugin.FDN4.Node.Menu.Values' : node=$node caller='max'
$text = read text: page=$PageID id=122
$storage = '(' + $curr + '/' + $max + ')'
$aStorage[0][1] = $text
$aStorage[0][3] = $storage
= wait 1000 ms
$active = get global variable: name=$is.active
end
CAUSES FREEZE
$a = array alloc: size=4
$a[0] = 1
$a[2] = 120
$aStorage = create new array, arguments=$a, [TRUE], null, null, null
$global = sprintf: pageid=$PageID textid=2041, $node, null, null, null, null
set global variable: name=$global value=$aStorage
while $active == 1
$curr = $node->get total volume in cargo bay
$curr = convert number $curr to string
$max = 50000000
$max = convert number $max to string
$text = read text: page=$PageID id=122
$storage = '(' + $curr + '/' + $max + ')'
$aStorage[0][1] = $text
$aStorage[0][3] = $storage
= wait 1000 ms
$active = get global variable: name=$is.active
end
Open script which updates the required values to global array (script1)
Open Menu (script 2)
Use a third script (script3) called by (script1) when you need to return a value from an object.
My FDN Nodes now have menus which dynamically update the storage used, just like in-game menus
The issue I have now is that the menu won’t show dynamic updates when the menu item which is global is referred from within a while loop, say you want to list wares and their amounts.
LA
Most likely the problem is, that you are not really changing the underlying array values, but something else. So, if the values are not updated dynamically, you should check if you're altering the correct values.The issue I have now is that the menu won’t show dynamic updates when the menu item which is global is referred from within a while loop, say you want to list wares and their amounts.
This is most likely because of the following command "$curr = convert number $curr to string". This command is very picky about its arguments, which must be an integer. Because this mistake happens a lot, I even wrote myself a small library script, which checks if the argument is really an integer before transforming it.Code: Select all
CAUSES FREEZE
Greetings,
ScRaT
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
Thanks for the pointers and great guide.
I've learnt a fair bit about what doesn’t work
I'm going to keep the value recovery on a separate script to the ONE which edits the globals. I'm working with a number of values (wares, volume, amounts in/out, bought/sold & cost/profits); having it all on one script makes it hard to track and debug.
LA
I've learnt a fair bit about what doesn’t work
I'm going to keep the value recovery on a separate script to the ONE which edits the globals. I'm working with a number of values (wares, volume, amounts in/out, bought/sold & cost/profits); having it all on one script makes it hard to track and debug.
LA
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
Please help my melting brain!
Hi,
I hope someone can help as I've tried every approach I can think of.
Basically I want to get a list of ware displayed with dynamically updated amounts.
[ external image ]
I have the Storage line of the menu updating okay, but no matter what I try the ware amounts won't change.
I have the menu script file
A dynamic script file which updates the values to global variables
And another script which the dynamic requests the data from.
Fist the dynamic one:
The 'plugin.FDN4.Menu,Values' just formats and returns the values rather than have everything on one page.
I've tested that everything is saved to global by writing to log book (lines 047 to 053)
As far as I can see this should work fine, the only difference to this and other dynamic menus I have running is the loop through a wares array.
This is segments of the menu:
This bit gets the storage:
This bit displays it:
As I've said the storage works okay.
This is what I'd hoped would give me updated ware amounts
I hope someone can point out what I'm doing wrong From the pic you can see that the menu gets the initial values as they are displayed okay, it's just not updating...
LA
I hope someone can help as I've tried every approach I can think of.
Basically I want to get a list of ware displayed with dynamically updated amounts.
[ external image ]
I have the Storage line of the menu updating okay, but no matter what I try the ware amounts won't change.
I have the menu script file
A dynamic script file which updates the values to global variables
And another script which the dynamic requests the data from.
Fist the dynamic one:
Code: Select all
000 $PageID = 9910
001 load text: id=$PageID
002
003 $is.active = sprintf: pageid=$PageID textid=2040, $node, null, null, null, null
004 $active = get global variable: name=$is.active
005
006 * Storage
007 $a = array alloc: size=4
008 $a[0] = 1
009 $a[2] = 120
010 $aStorage = create new array, arguments=$a, [FALSE], null, null, null
011 $global = sprintf: pageid=$PageID textid=2041, $node, null, null, null, null
012 set global variable: name=$global value=$aStorage
013
014 while $active == 1
015
016 $curr = [THIS]->call script 'plugin.FDN4.Menu.Values' : node=$node ware=null caller='curr'
017 $max = [THIS]->call script 'plugin.FDN4.Menu.Values' : node=$node ware=null caller='max'
018 $text = read text: page=$PageID id=122
019 $aStorage[0][1] = $text
020 $storage = '(' + $curr + '/' + $max + ')'
021 $aStorage[0][3] = $storage
022
023 $wareArray = [THIS]->call script 'plugin.FDN4.Menu.Values' : node=$node ware=null caller='wareArray'
024 $s = size of array $wareArray
025 while $s > 0
026 dec $s =
027 $ware = $wareArray[$s]
028
029 $a = array alloc: size=6
030 $a[0] = 1
031 $a[2] = 190
032 $a[4] = 270
033 $aWare = create new array, arguments=$a, $ware, null, null, null
034 $pointer = sprintf: pageid=$PageID textid=2001, $ware, null, null, null, null
035 set global variable: name=$pointer value=$aWare
037
038 $wareName = [THIS]->call script 'plugin.FDN4.Menu.Values' : node=$node ware=$ware caller='wareName'
039 $aWare[0][1] = $wareName
040 $wareAmt = [THIS]->call script 'plugin.FDN4.Menu.Values' : node=$node ware=$ware caller='wareAmt'
041 $aWare[0][3] = $wareAmt
042 $wareCap = [THIS]->call script 'plugin.FDN4.Menu.Values' : node=$node ware=$ware caller='wareCap'
043 $aWare[0][5] = $wareCap
045
046 * Test write to log file to ensure values written to global
047 $gWareArray = sprintf: pageid=$PageID textid=2001, $ware, null, null, null, null
048 $TestWare = get global variable: name=$gWareArray
049 $val1 = $TestWare[0][1]
050 $val2 = $TestWare[0][3]
051 $val3 = $TestWare[0][5]
052 $text = $val1 + ' - ' + $val2 + ' - ' + $val3
053 write to log file 09910 append=[TRUE] value=$text
054
055 end
056
057 = wait 1000 ms
058 $active = get global variable: name=$is.active
059
060 end
061 return null
I've tested that everything is saved to global by writing to log book (lines 047 to 053)
As far as I can see this should work fine, the only difference to this and other dynamic menus I have running is the loop through a wares array.
This is segments of the menu:
This bit gets the storage:
Code: Select all
$gStorage = sprintf: pageid=$PageID textid=2041, $node, null, null, null, null
$storage = get global variable: name=$gStorage
Code: Select all
$infoHeader = array alloc: size=0
append 1 to array $infoHeader
$text = read text: page=$PageID id=121
append $text to array $infoHeader
append 120 to array $infoHeader
$id = $node->get ID code
$text = '' + $id
append $text to array $infoHeader
add custom menu item to array $menu: text=$infoHeader returnvalue=null
* Storage Dynamic Update
append $storage to array $menu
This is what I'd hoped would give me updated ware amounts
Code: Select all
$text = read text: page=$PageID id=126
add custom menu heading to array $menu: title=$text
$arrayWare = $node->get tradeable ware array from station
$arrayWare = sort array $arrayWare
$arrayWare = reverse array $arrayWare
$s = size of array $arrayWare
if $s > 0
$waresHeader = array alloc: size=0
$text1 = read text: page=$PageID id=127
$text2 = read text: page=$PageID id=128
$text3 = read text: page=$PageID id=129
append 1 to array $waresHeader
append $text1 to array $waresHeader
append 190 to array $waresHeader
append $text2 to array $waresHeader
append 270 to array $waresHeader
append $text3 to array $waresHeader
add custom menu item to array $menu: text=$waresHeader returnvalue=null
while $s > 0
dec $s =
$ware = $arrayWare[$s]
$gWareArray = sprintf: pageid=$PageID textid=2001, $ware, null, null, null, null
$aWare = get global variable: name=$gWareArray
* Ware Dynamic Update
append $aWare to array $menu
end
$text = read text: page=$PageID id=138
add custom menu item to array $menu: text=$text returnvalue='addWare'
else
$text = read text: page=$PageID id=138
add custom menu item to array $menu: text=$text returnvalue='addWare'
end
LA
Well, I looked into your code and maybe I found the problem.
To make it clear to you, compare the two code segments from your sourcecode:
In the first segment you pre-create a menu item and fill it during the $is.active - loop.
In the second segment you always create a new menu item from scratch, so as I said, you don't change the underlying value of the menu array, but you create a completely new array.
Why is that so?
If you think of a menu as something that displays bits and bytes, located in the storage of your RAM, when you change the bits and bytes in that area, the menu will change. You, on the other hand, create a completely new array, which is located somewhere in the RAM, but definetely not in the area the menu is displaying. So the menu is not updating.
To solve your problem, you need to pre-create the menu items for each ware, as you did with the storage and update them in the $is.active - loop.
Greetings,
ScRaT
To make it clear to you, compare the two code segments from your sourcecode:
Code: Select all
007 $a = array alloc: size=4
008 $a[0] = 1
009 $a[2] = 120
010 $aStorage = create new array, arguments=$a, [FALSE], null, null, null
011 $global = sprintf: pageid=$PageID textid=2041, $node, null, null, null, null
012 set global variable: name=$global value=$aStorage
...
014 while $active == 1
019 $aStorage[0][1] = $text
020 $storage = '(' + $curr + '/' + $max + ')'
021 $aStorage[0][3] = $storage
COMPARED TO
014 while $active == 1
...
029 $a = array alloc: size=6
030 $a[0] = 1
031 $a[2] = 190
032 $a[4] = 270
033 $aWare = create new array, arguments=$a, $ware, null, null, null
034 $pointer = sprintf: pageid=$PageID textid=2001, $ware, null, null, null, null
035 set global variable: name=$pointer value=$aWare
In the second segment you always create a new menu item from scratch, so as I said, you don't change the underlying value of the menu array, but you create a completely new array.
Why is that so?
If you think of a menu as something that displays bits and bytes, located in the storage of your RAM, when you change the bits and bytes in that area, the menu will change. You, on the other hand, create a completely new array, which is located somewhere in the RAM, but definetely not in the area the menu is displaying. So the menu is not updating.
To solve your problem, you need to pre-create the menu items for each ware, as you did with the storage and update them in the $is.active - loop.
Greetings,
ScRaT
-
- Posts: 2255
- Joined: Mon, 31. Oct 05, 08:44
OMG yep, your right.ScRaT_GER wrote:Well, I looked into your code and maybe I found the problem.
To make it clear to you, compare the two code segments from your sourcecode:In the first segment you pre-create a menu item and fill it during the $is.active - loop.Code: Select all
007 $a = array alloc: size=4 008 $a[0] = 1 009 $a[2] = 120 010 $aStorage = create new array, arguments=$a, [FALSE], null, null, null 011 $global = sprintf: pageid=$PageID textid=2041, $node, null, null, null, null 012 set global variable: name=$global value=$aStorage ... 014 while $active == 1 019 $aStorage[0][1] = $text 020 $storage = '(' + $curr + '/' + $max + ')' 021 $aStorage[0][3] = $storage COMPARED TO 014 while $active == 1 ... 029 $a = array alloc: size=6 030 $a[0] = 1 031 $a[2] = 190 032 $a[4] = 270 033 $aWare = create new array, arguments=$a, $ware, null, null, null 034 $pointer = sprintf: pageid=$PageID textid=2001, $ware, null, null, null, null 035 set global variable: name=$pointer value=$aWare
In the second segment you always create a new menu item from scratch, so as I said, you don't change the underlying value of the menu array, but you create a completely new array.
Why is that so?
If you think of a menu as something that displays bits and bytes, located in the storage of your RAM, when you change the bits and bytes in that area, the menu will change. You, on the other hand, create a completely new array, which is located somewhere in the RAM, but definetely not in the area the menu is displaying. So the menu is not updating.
To solve your problem, you need to pre-create the menu items for each ware, as you did with the storage and update them in the $is.active - loop.
Greetings,
ScRaT
Good job it's not my day job!
Thanks I'll give it a go
LA
Edit:
Works like a dream, so happy , and again thanks.