News:

Simutrans Tools
Know our tools that can help you to create add-ons, install and customize Simutrans.

Menubar icon for scripted tool

Started by jameskuyper, May 17, 2025, 04:47:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jameskuyper

I've got a script that I've tested as the start() function of both a scenario script and an ai script. Both scripts worked, but what I learned from testing them is that it would make more sense as the work() function of a tool script. And that's where I run into a problem. There's something I'm not doing correctly, and as result no button shows up on the game menu for my tool. Since my squirrel code never gets a chance to execute, I doubt that it's relevant. Here's all the things I can think of that might be relevant:

From the Squirrel API,
QuoteRecommended directory structure
The script file (tool.nut) as well as the configuration file (description.tab) go into
pak-something/tool/mytool/
Related pak-files have to be placed in
pak-something/
directly.
The file description.tab
...
icon=Name of cursor object (loaded from some pak-file), used images: 0 = cursor, 1 = icon, 2 = marker image

Somewhere along the line I downloaded pak64.german with some tools. I examined config/menuconf.tab files and the description.tab files for those tools, and followed the naming conventions used in those files.

This is my description.tab:
title=Station Grid
type=one_click
tooltip=Places markers on the upper right corner of each 2x2 area that should contain passenger/mail stations.
restart=0
menu=SCRIPT_TOOL_STATION_GRID
icon=script_tool_station_grid

Based upon the Wiki page for cursors, I created the following cursor.dat file:
obj=cursor
Name=script_tool_station_grid
Image[0]=cursor.script_tool_station_grid.png
Image[1]=icon.script_tool_station_grid.png
Image[2]=marker.script_tool_station_grid.png

I'm planning to test this script using one of the simplest paks I could find, pak64.scifi. The config/menuconf.tab file says that icon_width and icon_height are both 32. Reading the wiki pages on creating graphics, I used Gimp to create a 32x32 24 bit png icon with no Alpha layer, avoiding all of the colors that have special meanings for simutrans. Having exhausted my artistic creativity creating that icon, I made three copies of it, named as indicated in the cursor.dat file.

I executed the following command line:
makeobj PAK script_tool_station_grid.pak cursor.dat

I've simplified the above description by removing every mistake I made and corrected, but in the end I carried out all of the above steps without generating any error messages.

As I understand it, this should result in my custom icon appearing on the right end of the map-editing menubar, but when I start a new game using pak64.scifi, it doesn't appear. Do you have any idea why?

Andarix

Copy makeobj to the attached files in a folder and run
makeobj PAK in a terminal.

The following must be entered in the description.tab.
icon=script_tool_undefined

The pak file must be in the pak folder.

The tool name must then be entered in the menuconf.tab.

Quotetoolbar[bar id][pos nr]=scripts(toolname)

Specifying menu= in the description.tab only makes sense to include several similar tools.

jameskuyper

When I invoked makeobj that way, I got error messages that didn't happen when I used it as indicated in my earlier message, which is an improvement. Firstly, it indicated that it couldn't find cursor.png, which is reasonable, because I didn't create any file of that name. However, why was it looking for such a file? If the image[0] value doesn't control what file name it is looking for, what is the purpose of image[0]?
I made corresponding changes to all of the image file names, and then got a message saying:

FATAL ERROR: while loading PNG - Invalid image size in ./cursor.png.

Gimp claims that the image is 32x32 with no Alpha channel. I've attached a copy of the image. What do I need to change to make it work? I can use any free Linux tool.

In pak64.german/menuconf.tab, it says
toolbar[14][2]=scripts(SCRIPT_TOOL_UPGRADE)
In pak64.german/tool/upgrade_bridge/description.tab it says
menu=SCRIPT_TOOL_UPGRADE
I've tested, and the upgrade bridge tool shows up properly when I use pak64.gernam. You indicated that I don't need to set "menu=" in description.tab, but that I do need to use scripts(tool name) in menuconf.tab. The description of "title=" says that it is the "Name of tool" - is that what I should be using? Why is there a difference between what you recommend and what the pak64.german tools do?

prissi

If you use a 32x32 imagae, you need to invoke makeobj with the pak32 parameter. The numbers after pak are the image sizes makeobj expects. pak stands for pak64.

jameskuyper

I created 32x32 images because pak64.scifi/config/menuconf.tab says icon_width=32 and icon_height=32. I just tried creating the pak file for this tool using PAK32, and it worked. I also tried creating a pak file using PAK and 64x64 image files.
However, when I started a new game using pak64.scifi, neither of those pak files resulted in a corresponding icon appearing in the game menu. What am I missing?

prissi

The entry toolbar[12][11]=scripts( will not do. First, the elements in a toolbar needs inreasing number, it must be 12. And then look at pak64.german, how the scripting tools are called.

Andarix

Quote from: Andarix on May 17, 2025, 07:07:38 AM...
The tool name must then be entered in the menuconf.tab.

Specifying menu= in the description.tab only makes sense to include several similar tools.

My mistake, you have to specify a name in the description.tab with menu=, which is then entered in the menuconf.tab.

description.tab
title=Station_Grid
type=one_click
tooltip=Places markers on the upper right corner of each 2x2 area that should contain passenger/mail stations.
restart=0
icon=script_tool_station_grid
menu=mark_grid

menuconf.tab pak64.scifi
toolbar[12][12]=scripts(mark_grid)
However, your tool code is flawed and won't work.

The mark_tile function is also only available in script scenarios, not in script tools.

jameskuyper

:question:
On the tool interface page, the description for mark_tiles() says "Call mark_tile from here."

The tool only functions page lists mark_tile() as a function that can ONLY be called from tool scripts.

jameskuyper

I'm not sure what happened to the menuconf.tab file. At one point, it had an entry that looked just like your correction. I don't know how or when it got damaged to be incomplete as I posted it.

Andarix

Quote from: jameskuyper on May 24, 2025, 05:34:16 PM....
The tool only functions page lists mark_tile() as a function that can ONLY be called from tool scripts.


QuoteDetailed Description
These classes and methods are only available for scripted scenarios.

jameskuyper

I repaired the menuconf.tab file as pointed out by Prissi. I changed the tool code to use tile.mark() rather than mark_tile(tile). I tried using the 32x32 pixel images packed using PAK32, and the 64x64 pixel images packed using PAK. No matter what I tried, when I started a new pak64.scifi game, I could not find my customized icon in the expected location on the map editing menu.
Any suggestions?

prissi

Maybe post everything, so we can have a look as with the menuconf.tab it is very easy to make errors.

Andarix

The menu you selected is only available to public players.

Screenshot 2025-05-30 070759.png

Otherwise, I can't help you, as you seem to mean something different than what you've written here.


jameskuyper

I'm unclear about whether I should create a pak64 file, because I'm targeting pak64.scifi, or a pak32 file, because pak64.scifi/config/menuconf.tab says
icon_width = 32
icon_height = 32

Therefore, I created 32x32 and 64x64 images in two different directories. For each size, I linked the images into the same directory as the curson.dat file and ran makeobj with either PAK32 or PAK, as appropriate, and then moved the resulting .pak file back into the same directory as the images. I linked each of the .pak files into the same directory as the description.tab and tool.nut files for my actual tests. It was not my intention to maintain this complicated structure for very long, just long enough to find out which size worked, and then I would simplify it. Since nothing worked, I haven't simplified it yet.

jameskuyper

Quote from: Andarix on May 30, 2025, 05:13:42 AMThe menu you selected is only available to public players.

That's not a problem. This tool is meant to be used by the public service player. In fact, that's why I wasn't satisfied with implementing it as the start() function for a scenario or ai script. I found that putting it in a scenario removed my ability to switch to the public service player. I also found that you can't assign an AI to the public service player.

Quote from: Andarix on May 30, 2025, 05:13:42 AMScreenshot 2025-05-30 070759.png

Otherwise, I can't help you, as you seem to mean something different than what you've written here.
I was meaning to ask you about that. Where did you get "mark_grid" from? I don't remember using that identifier anywhere. It's not in the current version of my files.

jameskuyper

I almost forgot.

Andarix

Quote from: jameskuyper on May 30, 2025, 06:03:53 PMI'm unclear about whether I should create a pak64 file, because I'm targeting pak64.scifi, or a pak32 file, because pak64.scifi/config/menuconf.tab says
icon_width = 32
icon_height = 32


Therefore, I created 32x32 and 64x64 images in two different directories. For each size, I linked the images into the same directory as the curson.dat file and ran makeobj with either PAK32 or PAK, as appropriate, and then moved the resulting .pak file back into the same directory as the images. I linked each of the .pak files into the same directory as the description.tab and tool.nut files for my actual tests. It was not my intention to maintain this complicated structure for very long, just long enough to find out which size worked, and then I would simplify it. Since nothing worked, I haven't simplified it yet.

The cursor.*.pak belongs in the pak64.scifi folder and not in pak64.scifi/tool/tool_folder.

Simutrans does not read pak files from the tool folder.