Scripting Update

For the programmers out there, I've added in a couple new interesting functions into the API. I'll harass Stephen and get him to update the manuals with them shortly, but here's a sneak peek.

Global Variables:

In all your scripts you can now set and maintain global variables, using the functions: setGlobal(int index,variable data), and getGlobal(int index). Where data can be a string, int, float, or boolean. There are ten globals available to you (0-9).

Here's an example of a poll I made for my website using them:

First I made a watch script for reseting the variables, I just installed it as a petty-cash watch and fire it when I want to reset the poll:

setGlobal(0,0);
setGlobal(1,0);
setGlobal(2,0);
setGlobal(3,0);
message("192.168.2.002","Poll Reset: "+getGlobal(0)+" "+getGlobal(1)+" "+getGlobal(2)+" "+getGlobal(3));

Next there is the actual HTTP script I made for allowing players to vote using my global variables, this is placed in the 'submit' event.:

string a=getParameter("a");
if(equal(a,"0")){
	int i=getGlobal(0);
	i=i+1;
	setGlobal(0,i);
}else if(equal(a,"1")){
	int i=getGlobal(1);
	i=i+1;
	setGlobal(1,i);
}else if(equal(a,"2")){
	int i=getGlobal(2);
	i=i+1;
	setGlobal(2,i);
}else if(equal(a,"3")){
	int i=getGlobal(3);
	i=i+1;
	setGlobal(3,i);
}

float a=getGlobal(0)*1.0;
float b=getGlobal(1)*1.0;
float c=getGlobal(2)*1.0;
float d=getGlobal(3)*1.0;
float total=a+b+c+d;
string message="<h1>Results</h1><p>Who is the sexiest developer of Hack Wars?</p>";
message=message+"Johnny Heart: "+(a/total*100.0)+"%<br />";
message=message+"Furrot: "+(b/total*100.0)+"%<br />";
message=message+"Alexander: "+(c/total*100.0)+"%<br />";
message=message+"Geckotoss: "+(d/total*100.0)+"%<br />";
popUp(message);

And, finally, we have the actual HTML I throw up on my page on Hack Wars. These together give my site a working poll:


<p> Who is the sexiest developer of Hack Wars? </p> <input type="radio" name="a" value="0" />Johnny Heart<br /> <input type="radio" name="a" value="1" />Furrot<br /> <input type="radio" name="a" value="2" />Alexander<br /> <input type="radio" name="a" value="3" />Geckotoss<br /> <input type="submit" value="Vote" /> </form>

Trigger Watch:

Ever want to attack the bank of someone visiting your website? now you can with the new HTTP function triggerWatch(int). Trigger watch takes an integer as input representing the numerical order (from top to bottom) of a watch in your watch handler. When someone enters your website, leaves your website, or submits a form, you can use trigger watch to activate one of your watches... I suggest counterAttackBank().

Comments

BOO YA!!!

All I can say is :D :D :D :D :D

I was thinking of requesting both of these features but wasn't sure if it you guys would go for it! This opens up some GREAT opportunities!

From :D

From Wartt Hog

Nice! Any chance

Nice!
Any chance get/setGlobal could take a string as argument instead of an int? Would make it more useful by
1) removing the 10 variable limit,
2) making them script-specific (ex: myBankScript-1, myBankScript-2)
3) allowing them to be used like arrays

I'm probably not going to

I'm probably not going to remove the 10 variable limit... Trying to keep the save files per player to a minimum, I figure if you program them creatively you can do tons of neat stuff, keep in mind nothing is stopping you from packing more information into the variable you set and parsing it out, e.g., setting 153 and parsing the '1' ,'5' , and '3' as individual parameters. They already are pretty much accessed like an array except for the [] syntax, which would require updates to the scripting language that probably aren't worth the trouble.

Using globals don't work

Using globals don't work since today.... yesterday it worked fine!
No script with setGlobals/getGlobals in it does anything.
It doesnt even trigger.... Don't know where the problem is.... but i think it's not my fault!
Did you patch anything today?

The following script works

The following script works fine for me as of a few seconds ago... Are you sure yours worked before with no special pre-conditions?... If globals aren't initialized every time you log on, using them makes things go screwy...

setGlobal(5,"test");
setGlobal(6,0);
setGlobal(7,0.5);
message("169.254.0.0",""+getGlobal(5)+getGlobal(6)+getGlobal(7));

(this was executed via a bank script and sent to me (169.254.0.0) the following output, "test00.5")

Ok I'm sure it is a bug

Ok I'm sure it is a bug now.
You were right, I have to reinitialize the global i wanna read.
But that's not the way it should make any sense...

If I wanna store the results like in the http poll above, it's senseless to reinitialize globals again, because I have to overwrite their values.
Well, I tried setGlobal(0,getGlobal(0)); but it didn't work too.

It seems that if u use getGlobal(x) in any script and are offline for a while (~24hrs for me), then the whole script doesn't work, until you reinitialize that global with a complete new value.

Possibly there was a server reboot or something, I can't exclude. But even if I close my browser, and then relog to the game, my globals are still working fine, if they did before. (Just some minutes between setting them, closing everything and the relogging and reading them.) But as I said, if I'm doing the same over a time period of 24hrs, globals are crashed!

@devs: Can you please make a statement about this problem? All my global scripts wont work, if i can't store anything for a longer time... I'm sure globals were not intented like this! Please fix that problem asap!!!!