Change actors/thinkers variables from menu

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Change actors/thinkers variables from menu

Post by Apeirogon »

Is it possible, and how, to change some variables of some thinkers/actors using custom menu, without using cvars?
Like, I create "actor statistic thinker", from which every actor on map can retrieve some informations. And I want to be able to change variables in this "actor statistic thinker", which all other actors on map can rertrieve, using menu system.

I cant use cvar for what I want, mostly statistic and debug data like average player speed/monsters damage/height/colour of blood/birth sign of the zodiac/relationships in family/etc., because this is required A LOT of cvars.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49095
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Change actors/thinkers variables from menu

Post by Graf Zahl »

You have to go through an event. The menu cannot access play data directly. That needs to be synchronized with the play loop.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Change actors/thinkers variables from menu

Post by Apeirogon »

I change something in menu - menu send data to network event - event send data to thinker - thinker save/send data to actors?
Or you mean "create console event and change all from console"?
User avatar
Caligari87
Admin
Posts: 6182
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him

Re: Change actors/thinkers variables from menu

Post by Caligari87 »

Apeirogon wrote:I change something in menu - menu send data to network event - event send data to thinker - thinker save/send data to actors?
This is the correct way, yes.

8-)
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Change actors/thinkers variables from menu

Post by Apeirogon »

Okay, but the question still actual. I dont know how send menu data to event/read data from event using menu.
A little example would be helpful and also grant plus to karma :3: .
User avatar
krokots
Posts: 266
Joined: Tue Jan 19, 2010 5:07 pm

Re: Change actors/thinkers variables from menu

Post by krokots »

OK here is simplest example I could make in couple of minutes.

ZScript classes

Code: Select all

Class MyMenu : ListMenu
{

	override bool MenuEvent (int mkey, bool fromcontroller)
	{
		switch (mkey)
		{
		case MKEY_Back:
			Actor player = players[consoleplayer].mo;
			int currentPlayerHealth = player.Health;
			MyEventHandler.SendNetworkEvent("myevent_name", currentPlayerHealth, 0, 0);			
			Close();
			return true;
		default:
			return Super.MenuEvent(mkey, fromcontroller);
		}
		return false;	
	}	
}

Class MyEventHandler : EventHandler
{
	
	override void NetworkProcess(ConsoleEvent e)
	{
		int playerNumber = e.Player;
		let plr = players[playerNumber].mo;

		if(plr)
		{
			if(e.Name == "myevent_name")	
			{
				Console.printf("Player current health is : "..e.Args[0]);
			}
		}
	}
}
Menudef

Code: Select all

ListMenu "MyMenu"
{
	Class "MyMenu"
}
Mapinfo

Code: Select all

Gameinfo
{
	AddEventHandlers = "MyEventHandler"
}
In game in console to open the menu write "openmenu mymenu". Pressing escape will firstly get the info from player (reading data), and then send an event (sending data). The event only writes information, but you could use this to spawn things, etc, depending on variables send through the event function.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Change actors/thinkers variables from menu

Post by Apeirogon »

To add something in this menu, like options and submenu, I must use menudef-s "ListMenu "MyMenu" "?!

Also, how I can send data from thinker to menu/menu can read data from thinker? Or I can only send data from ui to play, but not backward?
User avatar
krokots
Posts: 266
Joined: Tue Jan 19, 2010 5:07 pm

Re: Change actors/thinkers variables from menu

Post by krokots »

Apeirogon wrote:To add something in this menu, like options and submenu, I must use menudef-s "ListMenu "MyMenu" "?!

Also, how I can send data from thinker to menu/menu can read data from thinker? Or I can only send data from ui to play, but not backward?
UI can read data, but can't modify data. You can only send network events and change data through that.
You could use thinker iterators to access thinkers in menu, or get data through player.
What do you want to add to menu? Nice example of a ZScript menu is from D4D, I used it as a base in my mod Familiar Doom, which also has ZScript menus, but a bit expanded (and not friendly to read for anyone but me unfortunately).
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Change actors/thinkers variables from menu

Post by Apeirogon »

Okay, get it.
Next, menu can have pointers to thinkers? Or I must iterate through it every time I open menu?

Well, d4d has a little, just a LITTLE bit, mess with it organizations. One part of menu refers to another part, which placed in other corner of a pack, so this is not for me.....at least now.

I want to add something like, as example, field "wasted ammo" which shows how much ammo, by type/class, player wasted by picking up ammo actors, which have more ammo then player can currently hold. Like, if yoou miss one shell to 100 and pick up shell box, you waste 19 shells to somewhere between 2.5 and 2.6417926 dimensions. I know how store such data

Code: Select all

virtual pickup time()
check if (self ammo amount + player ammo amount > ammo max amount)
{send to thinker(create thinker if needed) "player e.consoleplayers scope(thinker).waste = (self ammo amount + player ammo amount - ammo max amount) self.getclassname()"}
super.pickup time()
But how point menu to it?
User avatar
krokots
Posts: 266
Joined: Tue Jan 19, 2010 5:07 pm

Re: Change actors/thinkers variables from menu

Post by krokots »

Apeirogon wrote:Okay, get it.
Next, menu can have pointers to thinkers? Or I must iterate through it every time I open menu?

Well, d4d has a little, just a LITTLE bit, mess with it organizations. One part of menu refers to another part, which placed in other corner of a pack, so this is not for me.....at least now.

I want to add something like, as example, field "wasted ammo" which shows how much ammo, by type/class, player wasted by picking up ammo actors, which have more ammo then player can currently hold. Like, if yoou miss one shell to 100 and pick up shell box, you waste 19 shells to somewhere between 2.5 and 2.6417926 dimensions. I know how store such data

Code: Select all

virtual pickup time()
check if (self ammo amount + player ammo amount > ammo max amount)
{send to thinker(create thinker if needed) "player e.consoleplayers scope(thinker).waste = (self ammo amount + player ammo amount - ammo max amount) self.getclassname()"}
super.pickup time()
But how point menu to it?
Unfortunately you can't "save" data or pointers inside menus, so every time you open it, you need to somehow get this data. I used custom player class to store data. Just create another Player class to store data and then cast the default player class to your class.

Code: Select all

Class MyPlayer : PlayerPawn
{	
	Actor someActor;
	Thinker someThinker;

	int wastedAmmo;
}

Class MyMenu : ListMenu
{

	MyPlayer myPlayer;
	
	override void Init(Menu parent = NULL, ListMenuDescriptor desc = NULL)
	{
		myPlayer = MyPlayer(players[consoleplayer].mo);
		if(myPlayer.someActor != null)
		{
			someActor.Destroy();
		}		

	}
}
Did you look at the "example" menu in D4D ? Here, and here, that's what I was talking about. It's still a bit complicated, uses "Drawer" and "Element" classes, but you can get a gist how it works (after couple of hours of reading, or that's just me).

Wasted ammo - just store it in player class, and then in menu, get this data from player.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Change actors/thinkers variables from menu

Post by Apeirogon »

https://github.com/MajorCooke/Doom4Doom ... us.txt#L34
// this is magic and I have no idea where it runs from, just null it here
Looks like major open third eye, all chakras, learn how levitate and eat swords, while coding this :lol:

Okay, so there are no another way, only dig into d4d, or search another mods with complex menu system.
User avatar
krokots
Posts: 266
Joined: Tue Jan 19, 2010 5:07 pm

Re: Change actors/thinkers variables from menu

Post by krokots »

Apeirogon wrote:https://github.com/MajorCooke/Doom4Doom ... us.txt#L34
// this is magic and I have no idea where it runs from, just null it here
Looks like major open third eye, all chakras, learn how levitate and eat swords, while coding this :lol:

Okay, so there are no another way, only dig into d4d, or search another mods with complex menu system.
Yeah, and D4D is the simplest example I could find :D. You just have to start by making a menu which just displays "A" in a corner, but from there you will expand it, and add buttons and stuff.

Return to “Scripting”