Change actors/thinkers variables from menu
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!)
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!)
Change actors/thinkers variables from menu
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.
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.
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49056
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Change actors/thinkers variables from menu
You have to go through an event. The menu cannot access play data directly. That needs to be synchronized with the play loop.
Re: Change actors/thinkers variables from menu
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"?
Or you mean "create console event and change all from console"?
- Caligari87
- Admin
- Posts: 6174
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
- Contact:
Re: Change actors/thinkers variables from menu
This is the correct way, yes.Apeirogon wrote:I change something in menu - menu send data to network event - event send data to thinker - thinker save/send data to actors?
Re: Change actors/thinkers variables from menu
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 .
A little example would be helpful and also grant plus to karma .
Re: Change actors/thinkers variables from menu
OK here is simplest example I could make in couple of minutes.
ZScript classes
Menudef
Mapinfo
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.
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]);
}
}
}
}
Code: Select all
ListMenu "MyMenu"
{
Class "MyMenu"
}
Code: Select all
Gameinfo
{
AddEventHandlers = "MyEventHandler"
}
Re: Change actors/thinkers variables from menu
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?
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?
Re: Change actors/thinkers variables from menu
UI can read data, but can't modify data. You can only send network events and change data through that.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?
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).
Re: Change actors/thinkers variables from menu
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
But how point menu to 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()
Re: Change actors/thinkers variables from menu
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.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 dataBut how point menu to it?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()
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();
}
}
}
Wasted ammo - just store it in player class, and then in menu, get this data from player.
Re: Change actors/thinkers variables from menu
https://github.com/MajorCooke/Doom4Doom ... us.txt#L34
Okay, so there are no another way, only dig into d4d, or search another mods with complex menu system.
Looks like major open third eye, all chakras, learn how levitate and eat swords, while coding this// this is magic and I have no idea where it runs from, just null it here
Okay, so there are no another way, only dig into d4d, or search another mods with complex menu system.
Re: Change actors/thinkers variables from menu
Yeah, and D4D is the simplest example I could find . 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.Apeirogon wrote:https://github.com/MajorCooke/Doom4Doom ... us.txt#L34Looks like major open third eye, all chakras, learn how levitate and eat swords, while coding this// this is magic and I have no idea where it runs from, just null it here
Okay, so there are no another way, only dig into d4d, or search another mods with complex menu system.