Very often modders want to type strings in acs, but there are no available ways to do this. I made one - HUDInput. This works by the same way as chat, but separated from it.
int HudInput(int player, str prompt); // shows input dialog to player with given id (-1 is activator), returns 1 if success, 0 - if not (means that input dialog is already opened or player is chatting)
int CheckHudInput(int player); // returns 1 if player is typing, else returns 0
str GetHudInputString(int player); // returns string from player input
int GetHudInputInteger(int player); // returns integer from player input (if player typed letters instead of numbers, function will return 0)
fixed GethHudInputFixed(int player); // returns fixed value from player input
void HudInputStop(int player); // closes input dialog
/* Simple example */
script 1 enter
{
HudInput(-1, "Please enter your name");
while(CheckHudInput(-1)) { delay(1); }
print(s:"Your name is: ", s:GetHudInputString(-1));
HudInput(-1, "Please enter any integer");
while(CheckHudInput(-1)) { delay(1); }
print(s:"Your integer is: ", d:GetHudInputInteger(-1));
HudInput(-1, "Please enter any fixed value");
while(CheckHudInput(-1)) { delay(1); }
print(s:"Your fixed value is: ", f:GetHudInputFixed(-1));
}
/* This script waits for 10 seconds and generates random value if enter key isn't pressed by player. */
script 1 enter
{
int value;
int time;
HudInput(-1, "Please enter any value");
while (CheckHudInput(-1))
{
if (time == 35 * 10)
{
value = random(0, 255);
HudInputStop(-1);
}
time++;
delay(1);
}
if (time < 35 * 10)
value = GetHudInputInteger(-1);
print(s:"Your integer is: ", d:value);
}
Something about this seems incomplete. I don't see how the text is being handled by the player command buffer.
Edit: Yeah, nothing about this is implemented properly at all.
Last edited by edward850 on Tue Aug 05, 2014 11:03 am, edited 1 time in total.
I literally cannot understand what's going on with this code. You define player numbers in your "specifications" but otherwise never use them. You only ever pull the string/chatmode from the local session, and the string can only ever be created by the local session. It never even touches player commands, which makes it beyond unusable in almost every test case I can think of.
Demos and netgames be damned. Which is completely absurd for something that uses player numbers as part of its spec.
edward850 wrote:I literally cannot understand what's going on with this code. You define player numbers in your "specifications" but otherwise never use them. You only ever pull the string/chatmode from the local session, and the string can only ever be created by the local session. It never even touches player commands, which makes it beyond unusable in almost every test case I can think of.
Demos and netgames be damned. Which is completely absurd for something that uses player numbers as part of its spec.
Ok, that decides it. After reading this I had a closer look at the code and you are correct. This neither works with demos nor with multiplayer. Sorry, can't be added as-is.
Would be useful actually (I have at least 3 major uses for this if this were implemented) but I guess the implementation is incomplete. Once demo, save-game and multiplayer compatibility is properly worked out, I'm sure it'd be decent for inclusion.
Example usage: text entry with keyboard instead of ACS-based mouse-driven on-screen keyboard . For in-game journals, question/answer stuff, etc.
Well, I won't go in to a stylistic discussion there.
But needless to say, there's far nicer ways to get keyboard input there than hacking in to the chat functionality. I'd rather a full-fledged API that has properly thought things through than something that essentially replicates the BASIC prompts you used to type in to C64s in stores back in the day.
Basically, yeah. That's the other problem I had with this. It's rather kludged in with a function that made little sense from a user standpoint (why the chatmesseage function? Especially if you're not actually chatting to something), and it incorrectly assumed that players would always have some form of keyboard input (which is kind of a bad thing to assume these days).
It does make me wonder if it would be worth adding the virtual keyboard to the chatmessage function, though.
edward850 wrote:I literally cannot understand what's going on with this code. You define player numbers in your "specifications" but otherwise never use them. You only ever pull the string/chatmode from the local session, and the string can only ever be created by the local session. It never even touches player commands, which makes it beyond unusable in almost every test case I can think of.
Demos and netgames be damned. Which is completely absurd for something that uses player numbers as part of its spec.
This neither works with demos nor with multiplayer. Sorry, can't be added as-is.
You closed suggestion faster than I posted new comment. I made new version of patch that could help in netgames. I just added hud information to player's object.
Hope, this helps.
Last edited by Monsterovich on Thu Jan 08, 2015 1:49 pm, edited 3 times in total.
You don't even know what you are doing, do you? This fixes absolutely nothing about the issues pointed out. The Input still doesn't touch the player command buffer, and it will still break horribly in demos (I'm not sure how amused I'm supposed to be at the chat dialog popping up during demo playback).
And it's still pretty much the wrong way to go about any of this.