Is there a way to check for button / keyboard input with GS?

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Is there a way to check for button / keyboard input with GS?

Post by Openend »

Ive looked through the documentation and (so far) 4 other gamescripts, but not found the answer yet.

Is there a way to listen for input from the main game within a game script, to trigger a function for example, when the player presses a button or a key?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Is there a way to check for button / keyboard input with

Post by Zuu »

No.

You can use the query dialog which has up to 3 buttons from a set of pre defined captions. You can listen for the event when one of those are pressed. You will get the event at company level, so if many persons play at the same company, you'll see them all as one user. Thus the first one to click will win, but they do have team chat so they can talk among each other and decide what to do. After all many people on a single company will be in a cooperating team and not compete against each other.

A second option you have is to scan signs of companies and look for some sign commands. Eg. if a player create a sign with the text "!money" you can look for such signs once a while and when it is found, you remove it and give them money using the API for that.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Is there a way to check for button / keyboard input with

Post by Openend »

Thanks, that was what I needed. I was looking for a way to test changes quickly, for example, if I create a function to grow a city, I can trigger it fast and easy with this. Do you have more advise on quick tests of gamescripts?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Is there a way to check for button / keyboard input with

Post by Zuu »

Enable gui.ai_developer_tools so you get the break-on-log-message feature as well as AIController::Break() to add a break point inside your code.
http://wiki.openttd.org/AI:Need_To_Know ... og_message

Edit: you may also check out the sign related helpers in SuperLib. Some of them are older than the debugging support in OpenTTD, but may still be of use depending on what fit you. As you may be aware of, when writing a GS, use GSCompanyMode to specify as which company you want to access signs etc.

Code: Select all

	//////////////////////////////////////////////////////////////////////
	//                                                                  //
	//  Sign                                                            //
	//                                                                  //
	//////////////////////////////////////////////////////////////////////

	/* Note: An AI can only access its own signs. So you must use the
	 *   cheat dialog and switch to the AI company if you want to place
	 *   control signs such as "break_on" etc.
	 */

	/* Use this function instead of AISign.BuildSign to never build more 
	 * than one sign per tile 
	 *
	 * Signs are only placed if the AI setting debug_signs is equal to 1
	 *
	 * Returns: The sign id of the sign that is placed/updated or -1
	 *   if no sign is created/updated.
	 */
	static function SetSign(tile, message, force_build_sign = false);

	/* Puts a "break" sign on the given tile and waits until that sign
	 * gets removed by the player. Usefull for debuging.
	 * 
	 * Break points are only placed if AI setting debug_signs == 1 or
	 * if the sign "break_on" is present. In either case if the sign
	 * "no_break" is present then no break points will be placed.
	 * See the implementation if this text is not clear enough.
	 */
	static function BreakPoint(sign_tile, force_break_point = false);

	/* Checks if the AI has a sign with the given text */
	static function HasSign(text);

	/* Returns the id of the first found sign with given name. If no sign
	 * is found, -1 is returned. 
	 */
	static function GetSign(text);

	/* Checks if the AI has a sign at the given location */
	static function HasSignAt(tile);

	/* Returns the id of the first found sign at the given tile. If no sign
	 * is found, -1 is returned. 
	 */
	static function GetSignAt(tile);

	/* Removes all signs that the AI has. */
	static function ClearAllSigns(except_tile = -1);
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Openend
Engineer
Engineer
Posts: 36
Joined: 18 Jun 2015 09:09

Re: Is there a way to check for button / keyboard input with

Post by Openend »

Thanks! Ill play with this and report back if I stumble again :)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 45 guests