ACS Strings

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
aabra
Posts: 21
Joined: Wed Apr 26, 2006 8:46 pm

ACS Strings

Post by aabra »

I was talking about perhaps adding an ACS function called getname() to the Skulltag/Zdoom ACS which would return the name of the player so you could assign it to a variable earlier in the Skulltag forums.

I was thinking something along the lines of

playername = getname()

However I was informed that ACS doesn't support dynamic strings making this type of function impossible even though in print statements you can use n:0 to refer to the player who activated the script. I was just wondering if this was true or not. Would something like this really be virtually impossible to implement? (Without making *serious* changes to the way ACS works)

Would a hackish solution be possible so that a statement like this would work?

playername = n:0

I'm just curious and looking for confirmation is all as this is something I'd really like to harass somebody into adding eventually and it'd be a bit depressing if it's not at all possible.
User avatar
Zippy
Posts: 3302
Joined: Wed Mar 23, 2005 5:31 pm
Location: New Jersey

Post by Zippy »

I may be mistaken, but n:<someNumberHere> should let you print any given player's name. In fact, I'm really pretty confident it should because off the top of my head I'm remembering HotWax's Catch the Chicken score board, which did make use of the player's names.

In essence you really shouldn't need any more. The only thing you can do with strings in ACS is output them or pass them to functions that take them specifically (and none of those would have anything useful to do with a player's name.) Is there some specific reason you want to be storing a player's name in a variable? I'm pretty confident that anything you want to get done by storing a player name in a variable could easily be done in an alternate fashion without it.
User avatar
Necromage
Posts: 484
Joined: Thu Feb 10, 2005 3:13 pm
Location: NJ
Contact:

Post by Necromage »

Simply, no. ACS does not have a system for dynamically producing strings. It is a limitation that I have tried to change but my lack of c++ skills and time have not enabled my to actually finish it.
User avatar
Risen
Posts: 5263
Joined: Thu Jan 08, 2004 1:02 pm
Location: N44°30' W073°05'

Post by Risen »

Zippy: He knows that.

aabra: Confirmation you shall have!
http://forum.zdoom.org/potato.php?p=217333
aabra
Posts: 21
Joined: Wed Apr 26, 2006 8:46 pm

Post by aabra »

Well, I was asked this by someone who wanted to add a 'high scores' list to his wad. The only thing I could tell him was if the player got a high score - teleport him to another room and have him enter his 3 initials ala oldschool arcade style.

This however doesn't permit the user to have his complete name and is really a bit of a meh solution. It'd be nice if you could save a player's name to a variable somehow and then spew it out later. Say a player connected to a server and as he entered it would say "Current Champion is Doogie Howser" or whatever. (But Doogie Howser of course had long since left the server.) I think that'd be neat.

Any ideas on how to do something like this?
User avatar
Necromage
Posts: 484
Joined: Thu Feb 10, 2005 3:13 pm
Location: NJ
Contact:

Post by Necromage »

Something based on this should work:

Code: Select all

#include "zcommon.acs"

int score[8] = {0,0,0,0,0,0,0,0}; //stores the score

script 1 void
{
     //who is the highest?
     int high = 0;
     for(int i = 0; i<8; i++) if(score[high] < score[i]) high = i;
     //print the highest
     printbold(n: high+1, s:" has the highest score");
}
Last edited by Necromage on Fri Sep 28, 2007 12:20 pm, edited 2 times in total.
aabra
Posts: 21
Joined: Wed Apr 26, 2006 8:46 pm

Post by aabra »

That will work even if the player is no longer connected?

I'll need to test that.
User avatar
Nash
 
 
Posts: 17500
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Post by Nash »

As long as you store the champion's name in a global or map variable, the name should stay there until you replace it with something else.

ALINV's last map, Seriously Unrealistic Quake prints out the name of the player who finds the BFG10K secret.

DTINV's last map also prints the name of the player who tries to bypass a certain force field in the later stages of the invasion.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Post by Gez »

Yeah, but imagine in a game player 8 (which we will call Some Dude) gets the high score early on.

The script says that Some Dude has the highest score.

Happy at his victory, Some Dude leaves the game as he has some work to do.

Now, the slot is free. What does the script say? Maybe it retains the last name. But let say that now that a slot is free, the game is joined by Random Chump, who becomes the new player 8. What happens?

I think the script will say that Random Chump has the highest score.
User avatar
Isle
Posts: 687
Joined: Fri Nov 21, 2003 1:30 am
Location: Arizona, USA

Post by Isle »

Nash: you cant store the name in a variable.

and when the player leaves the name goes too.
User avatar
MartinHowe
Posts: 2078
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Location: East Suffolk (UK)

Post by MartinHowe »

There's nothing theoretically impossible about adding strings to ACS, but the only way to do it without turning ACS into a whole new language would be to allow the internal string table to grow (and maybe shrink, though not below its initial size, since the literal strings in the script must be final) and use a C style strings.h lookalike with unique string IDs instead of pointers.

Lack of time and lots of other things to do prevents me, and I suspect other coders, from actually having a go at doing this.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Post by Gez »

Maybe you could imagine a function that would create a char array and use that as a string (the old C way). After all, a char is actually an int, and you can make an int array.
User avatar
Nash
 
 
Posts: 17500
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Post by Nash »

Thanks Isle. I totally forgot that the only way those WADs are retrieving the player's name is from the HUDMessage function.

Too bad. :(
User avatar
Necromage
Posts: 484
Joined: Thu Feb 10, 2005 3:13 pm
Location: NJ
Contact:

Post by Necromage »

aabra wrote:That will work even if the player is no longer connected?

I'll need to test that.
All you need to do is check if the player is in the game with [wiki]PlayerInGame[/wiki]. Then you can change this:

Code: Select all

for(int i = 0; i<8; i++) if(score[high] < score[i]) high = i;
with:

Code: Select all

for(int i = 0; i<8; i++) if(PlayerInGame(i)) if(score[high] < score[i]) high = i;
User avatar
Zippy
Posts: 3302
Joined: Wed Mar 23, 2005 5:31 pm
Location: New Jersey

Post by Zippy »

Risen wrote:Zippy: He knows that.
Not quite:
aabra wrote:However I was informed that ACS doesn't support dynamic strings making this type of function impossible even though in print statements you can use n:0 to refer to the player who activated the script.
which is quite a bit different that being able to access any player's name in a Print/HudMessage statement by their fixed numbers.
Post Reply

Return to “General”