feature request: pushcvar, popcvar

Discussion for Bani's Tournament Mod

Moderators: Forum moderators, developers

User avatar
SnowWhite
Posts: 22
Joined: Wed Dec 08, 2004 7:15 am
Location: Sweden

feature request: pushcvar, popcvar

Post by SnowWhite »

I hope this hasn't been brought up before. My sincere apologies if it has.

I'd like to request two console commands the likes of which I'm unaware of. The commands could be named "pushcvar" and "popcvar", and they would manipulate a stack of cvars.

The rationale for this request is mainly that such a stack would allow less cvars to be used in client scripts.

Proposed syntax:
pushcvar "from_cvar"; // pushes the string in "from_cvar" on top of the stack
popcvar "to_cvar"; // pops the topmost string from the stack and sets "to_cvar" to this string

'pushcvar' shouldn't perform any dynamic expansion or such, just handle the values in argument cvar. If argument cvar isn't set or is empty, a null string ("") should be pushed on stack.

'popcvar' should erase&replace any existing value in target cvar. If the string on top of the stack is a null string (""), or stack is empty, the target cvar should be removed. If the target cvar doesn't exist yet, and value on stack is not "", the target cvar should be created.

It also strikes me as a good idea to have a command to reset the stack. 'popall' or something, to reset stack pointer.

A stack like this could be further enhanced with a command like "pushstring", which could perform cvar expansion on its argument string ("vstr some_cvar; ..."), but that might make things too complicated. Pushcvar & popcvar would be powerful enough.
[DD]ZeDoX
Posts: 48
Joined: Wed Jun 23, 2004 5:23 pm

Post by [DD]ZeDoX »

Try posting in english
Image
User avatar
SnowWhite
Posts: 22
Joined: Wed Dec 08, 2004 7:15 am
Location: Sweden

Post by SnowWhite »

[DD]ZeDoX wrote:Try posting in english
cvar == a variable, container for a string of text
stack of cvars == a container for many values of cvars

You can think of a stack as an ammo magazine; you push one or more bullets (cvar values) down, you pop them back in reverse order.

Stack only allows to insert or retrieve one value at a time. Inserting is called "pushing", because you push a value on top of the stack, and all values already there are pushed "further down". Getting a value from the top of the stack is called "popping" it. If you push "1", then "2", then "3", you will pop first "3", then "2", then "1", i.e. in backward order.

Most basic use: if you need to temporarily change some cvar, you can "push" its value on the stack, change the cvar anyway you like, then after a while you can "pop" the value from the stack back into your cvar, and the original value is restored.
Additionally, you can use the push/pop mechanism to assign the value of one cvar to another.
SoL
Posts: 44
Joined: Fri Apr 23, 2004 9:37 am

Post by SoL »

do you even know what you're talking about? :?
User avatar
Lagger
Posts: 316
Joined: Mon Sep 29, 2003 8:30 am

Post by Lagger »

this is a WAAY to complex method of handling cvars, not to mention a world of fun to debug for the average scripter.

if all you want to do is copy the value of one cvar into another, something like my imaginary command "cpvar source dest" would be a lot more sane.
User avatar
SnowWhite
Posts: 22
Joined: Wed Dec 08, 2004 7:15 am
Location: Sweden

Post by SnowWhite »

Lagger wrote:this is a WAAY to complex method of handling cvars, not to mention a world of fun to debug for the average scripter.

if all you want to do is copy the value of one cvar into another, something like my imaginary command "cpvar source dest" would be a lot more sane.
It's easier than it seems, just need to get your head around it. :) Once people get used to the idea, it'll seem as obvious as "cpvar" that you suggest. Most "average" and not so average scripters juct copy&paste together their configs anyway, only a few of them will ever understand what's going on. So yes, initially it's for a selected few, but the masses will get their hands on the work of the few through the usual channels, as they always do.

Anyway, not saying your idea is bad. I'd be glad to have it for the lack of anything better, but it's not all I want to do. Ideally there'd be both stack-commands and assignment commands, and hey why not if/then/else blocks, but I'd be happy like a little boy with a new toy if we just got push&pop.
User avatar
jinx
Posts: 81
Joined: Sun Aug 29, 2004 10:17 am
Location: Illinois, USA

Post by jinx »

Code: Select all

<?
include 'db.php';
$query = "SELECT * FROM etpro_forums_user_list WHERE where users LIKE snow";
$result = mysql_query&#40;$query&#41; or die&#40;"Error"&#41;;
$numresults=mysql_query&#40;$query&#41;;
$numrows=mysql_num_rows&#40;$numresults&#41;;
if &#40;$numrows == 0&#41;
  &#123;
  echo "<h4>LIES! SEARCH AGAIN</h4>";
  &#125;
$users = $row&#91;'users'&#93;;
if&#40;$users == SnowWhite&#41; &#123;
echo&#40;"Your solution is a bit too complicated for a game!<br>"&#41;;
&#125; else &#123;
echo&#40;"Your name is too close to SnowWhite's, immediately change it.<br>"&#41;;
&#125;
echo&#40;"<a href=\"javascript&#58;window.history.back&#40;-1&#41;\">Go Back</a>"&#41;;
?>

I actually like the way you are going, but a pop and push would easily be substituted (with equal functionality, at least) with the "cpvar" solution. I do like the if, elseif, else idea :)
Image
User avatar
SnowWhite
Posts: 22
Joined: Wed Dec 08, 2004 7:15 am
Location: Sweden

Post by SnowWhite »

jinx wrote:I actually like the way you are going, but a pop and push would easily be substituted (with equal functionality, at least) with the "cpvar" solution. I do like the if, elseif, else idea :)
The solution I described is simple... but it seems to me that some people are more concerned about the way I described it, rather than the suggestion itself. ;) I realize there's a limit on how advanced a game should be, which is why I didn't ask for Perl integration or some such.

Now, push and pop can not be easily substituted with "cpvar", and functionality would not be equal. The opposite is true, however, you can simulate "cpvar" with push and pop. The main advantage of push/pop mechanism is that you don't need to use up any extra cvars for temporary storage (assuming you just wanted to save a few values for later use). I was lead to believe that there's a limit on how many cvars you can have in ET (max 1024?), so push/pop is just a way to 1) minimize the number of cvars in scripts by stuffing temporary values into an unnamed storage space and 2) allow cvar assignment. There may be other side effects, but I can't think of any negative (i.e. abusable).
The ability to assign cvars is not that useful on its own, since you can't print/output the values anyway (next step?), but ET Pro is eating more cvar slots with each new release, and so some solution for the MAX_CVARS problem needs to be found eventually.
User avatar
jinx
Posts: 81
Joined: Sun Aug 29, 2004 10:17 am
Location: Illinois, USA

Post by jinx »

I like the idea, it would be great - much more advanced scripts, and, once learned, much cleaner and easier to modify scripts. A language integration wouldn't be a bad idea :prof:
Image
User avatar
Lagger
Posts: 316
Joined: Mon Sep 29, 2003 8:30 am

Post by Lagger »

i just have a gut feeling that event based scripting and a stack storage doesn't work well together. any given event can't just pop from the stack, without pushing something on the stack. so you can't store anything in the stac between events, since there is no guarantee that some other event operated on the stack.

perhaps you could make an example of how your idea (as opposed to "cpvar") would be put to good use, because i really can't see it
User avatar
gotenks
Posts: 3465
Joined: Fri Nov 15, 2002 4:12 pm
Location: out of my mind
Contact:

Post by gotenks »

don't know if this is similar to what you're asking for (still trying to figure it out myself :lol:) but how about a way to edit 1 of the values in a cvar...
eg:
b_defaultskills (only one i can think of) so you can just change 1 number instead of all of them...
b_defaultskills "2 0 0 0 3 0 0"
to change the 2nd value (starting at 0 and incrimenting)
b_defaultskils[1] "2"
this would make
b_defaultskills "2 2 0 0 3 0 0"
My Website
Image
After a night of binge drinking:
=FF=im2good4u wrote:WTF wanst i on top ?
User avatar
SnowWhite
Posts: 22
Joined: Wed Dec 08, 2004 7:15 am
Location: Sweden

Post by SnowWhite »

Lagger wrote:i just have a gut feeling that event based scripting and a stack storage doesn't work well together. any given event can't just pop from the stack, without pushing something on the stack. so you can't store anything in the stac between events, since there is no guarantee that some other event operated on the stack.
Aye, good point. It would be failsafe if every event-script restored the stack to its original state before other events triggered other scripts, but that way you don't need a stack.
Lagger wrote:perhaps you could make an example of how your idea (as opposed to "cpvar") would be put to good use, because i really can't see it
I was fiddling with my hud-scripts, various things (crosshair, fov, etc) changing when you hold down a key, and going back to previous state on key release. I have different settings for different weapons, so restoring the "previous state" is not entirely trivial with the way scripts work now. I end up wasting a bunch of cvars, and I felt that a stack-like solution would be handy.

As you point out, there's no guarantee that events occur in the right order, people can hold down several keys at once and release them in arbitrary order, so a real cvar stack would be mangled (unless you took care not to release the keys in the wrong order, which is obviously not good enough).

Maybe it would be more feasible to have commands to simply save/restore the value of a cvar, like this:

"save cg_drawgun" -- equivalent to "cg_drawgun_org = cg_drawgun"
"restore cg_drawgun" -- equivalent to "cg_drawgun = cg_drawgun_org"

"cg_drawgun_org" being the storage location where the original value of cg_drawgun goes. Obviously, this temporary storage can't be a cvar itself, otherwise the point of using less cvars is lost.

Of course, it'd still be possible to write buggy scripts, but in a real-life scenario different events would typically save/modify/restore different cvars, and there wouldn't be a common stack for all events to mangle.

Whatcha think?
User avatar
WeblionX
Posts: 762
Joined: Sun Sep 08, 2002 1:03 pm
Contact:

Post by WeblionX »

Perhaps ETPro should release an API to the bind system/console and a guide to programming in C? ;)
Got any old idtech3 tutorials you made or saved? Send them my way.
User avatar
SnowWhite
Posts: 22
Joined: Wed Dec 08, 2004 7:15 am
Location: Sweden

Post by SnowWhite »

WeblionX wrote:Perhaps ETPro should release an API to the bind system/console and a guide to programming in C? ;)
Hey, good idea! I wouldn't mind if next version of etpro could load a few user-provided libs with routines for custom hud rendering and key-event handling. =) If servers get to run mods like etpro, why not introduce pure client-side mods, right? Oh, there are already? What's that? Hacks, you say? Dude!
User avatar
jinx
Posts: 81
Joined: Sun Aug 29, 2004 10:17 am
Location: Illinois, USA

Post by jinx »

Buggy scripts will happen. If I assign a value to a variable, and then 10 lines later assign another value to the same variable and call the variable expecting the original value, it will fail; no different than stacks changing. Three stacks would do, one stack is always kept original, another stack is pulled from, and the third stack is changed on. On every stack change, set the pulled from stack back to the original, change things through their and never worry about faulty code due to improper key press/removal. Simple, and would still save cvars.
Image
Post Reply