PDA

View Full Version : FQ Scripting



jjohn
06-12-2003, 03:29 PM
As look through the documentation (fqhelp/scripting.htm), example scripts (all of redink1's mods) and poke around on my own, I'm finding a number of "gotchas" with the FQ scripting language (which I call FQ-C). Here's my biggest beef:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
int i = -1;
int m = 10;

if &#40;i &#60; 10&#41;
{
m = 1 + i;
}

LogMsg&#40;&#34;i is &#036;i&#036; and m is &#036;m&#036;&#34;&#41;;
[/QUOTE]

I&#39;d expect the log message to read "i is -1 and m is 10". Unfortunately in FQ 0.94, the message is "i is -1 and m is 1."
If you switch the operands in the right hand expression, m gets -1.

It appears that the lvalue gets the closest term of the right hand expression. The value of the right hand expression is ignored.

Lest you think that this case is trivial, please note that I&#39;m attempting to implement while loops with goto statements, like the following:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
int i = 0;

loop&#58;
if &#40;i &#60; 10&#41;
{
i += i;
goto loop;
}

LogMsg&#40;&#34;i is &#036;i&#036;&#34;&#41;;
[/QUOTE]

Branching is good, but without looping FQ-C&#39;s potential is very limited. If the assigment bug gets fixed, FQ-C can loop with the best of &#39;em.

Seth, I know you&#39;re probably on to new things, but can you address this please? I&#39;m creating additional documentation for the scripting environment which I&#39;ll give to you when it&#39;s done.

jjohn
06-12-2003, 04:09 PM
Question 1:

I assume global variables are created as soon as they are declared. When are they destroyed? When the server shuts down? During maint?

Question 2:

There&#39;s a noticable lack of string manipulation primatives in FQ-C. How can two strings be concatinated? This is important. Consider this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
int i = 10;
String s;

s = &#34;i is &#036;i&#036;&#34;; // &#036;i&#036; isn&#39;t interpreted yet

LogMsg&#40;&#34;Here&#39;s a mesage&#58; &#036;s&#036;&#34;&#41;;
[/QUOTE]

In the logs, "Here&#39;s a message: &#036;s&#036;" appears instead of "Here&#39;s a message: i is 10".

How can two strings be tested for equality? Is there a strcmp function?

Question 3:

What&#39;s the function to get the current HP of a player? GetCurrentHP doesn&#39;t work (not that that is a documented function). If I can read the currentHP value, I can re-create fights or have the player fight random beasties. :-)

Question 4:

What happened to the function called AddButtonScript that appears commented out in church.c? Is it deprecated? Is it yet to be implemented? I understand that one can create a plain old button, and then call RunScriptNoReturn(), although I&#39;m sure the sematics are exactly the same.

Seth
06-12-2003, 10:39 PM
John, the FQ scripting language is pretty simplistic, mostly designed for fast psuedo compilation on load.

Globals are not saved. This language itself has the functionality to do this though, it&#39;s just not activated in FQ.


<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
a = 1+5;
[/QUOTE]
Is not supported. You would have to do:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
a = 1;

a += 5;

a /= 5; //division
[/QUOTE]

About "s = "i is &#036;i&#036;"; // &#036;i&#036; isn&#39;t interpreted yet"

s can be forced to be converted now by doing:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
s = ExpandString&#40;s&#41;;

//equality

if &#40;s == &#39;crap&#39;&#41;
{
if &#40;s &#62; 1&#41;
{
//s equals crap, and is also more than 1 letter in length of course&#33;
s += &#34; is not good&#34;
LogMsg&#40;s&#41;;

}
}
[/QUOTE]

About this snippet:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
int i = 0;

loop&#58;
if &#40;i &#60; 10&#41;
{
i += i;
goto loop;
}
[/QUOTE]

This should work fine. Note there is a bug, should be i += 1;

Hope this helps and can&#39;t wait to see your mod&#33;

jjohn
06-12-2003, 11:41 PM
Thanks for replying so quickly, Seth. I think the scripting language is up to the task of creating more flexibility in FQ. I&#39;m not working on a mod right now, but I am working on additional documentation for scripting FQ. That&#39;s why I&#39;m finding these edge cases.

RE: Globals. I understand that globals don&#39;t survive server shutdown, but am I correct in thinking that globals live *until* server shutdown?

RE: a = i + 5; Bummer, but thanks for the work-around.

RE: ExpandString(); Oh&#33; That&#39;s a nice one. Unfortunately, it doesn&#39;t appear to be enabled in FQ 0.94. I get this in the log:


Quote[/b] ]
WARNING: 06-12 7:47 PM:EXPANDSTRING is an undeclared function. (File: script&#92;public&#92;church.c - Line 49)


Should I peek at the Dink-C docs for more string functions?

More questions later. :-)

Seth
06-13-2003, 12:12 AM
Quote[/b] ]
RE: ExpandString(); Oh&#33; That&#39;s a nice one. Unfortunately, it doesn&#39;t appear to be enabled in FQ 0.94. I get this in the log:



Whups, try StringExpand().

There is no get HP mostly because HP really has no meaning in the game as it is always recharged before a fight - you could do:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
int i_hp = GetMaxHP&#40;player_id&#41;;

//have a big fight

i_hp -= i_damage; etc..
.. if &#40;i_hp &#60; 1&#41;
{
//player died
}
[/QUOTE]

Dink&#39;s documentation won&#39;t help much, but Teenage Lawnmowers will, as they use the same plugin scripting system. Install the Teenage Lawnmower editor (it&#39;s on TLM&#39;s download page) and check the docs it comes with, it has a pretty large scripting section, I think it covers string usage much better.

jjohn
06-13-2003, 02:11 AM
RE: maint_player.c

i_my_id should be defined in the script. In fact, I can
LogMsg("&#036;i_my_id&#036;") and see that it does have the right value.
But when I try to do:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
int has_ba = GetCustomByID&#40;i_my_id, C_CUSTOM_BODY_ARMOR&#41;;
[/QUOTE]

I get a log warning:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
WARNING&#58; 06-12 10&#58;08 PM&#58;i_my_id is an undeclared variable. &#40;File&#58; script&#92;maint_player.c - Line 14&#41;
[/QUOTE]

Help&#33;

Seth
06-14-2003, 10:44 AM
I already told you this in email today, but just for anyone else reading, this problem with the maint script is definitely a bug, looking into it. I don&#39;t think the "per player" maint script has ever been used before, which is why it wasn&#39;t noticed earlier.

jjohn
06-22-2003, 02:39 PM
I&#39;ve released the source code for Bingo Night, the Black Cat event and the Bonus Turn event. You can get them here:

http://aliensaliensaliens.com/~jjohn/fq/

I&#39;ve packaged these as zip files and the installation is pretty crude. If you&#39;ve got other mods on your system, unpack the archives in a temp directory first and Read The Fun Manual.

Also, I&#39;d like to continue to plug Dan Walma&#39;s FQ mods (that even have new graphics&#33;). His can be found here:

http://members.lycos.co.uk/redink1/fqmod/

redink1
06-23-2003, 01:53 AM
Um... thanks for the plug, but its Dan Walma, not Dan Wilma http://www.rtsoft.com/iB_html/non-cgi/emoticons/smile.gif

jjohn
06-23-2003, 02:04 AM
Quote[/b] (redink1 @ June 22 2003,9:53)]Um... thanks for the plug, but its Dan Walma, not Dan Wilma http://www.rtsoft.com/iB_html/non-cgi/emoticons/smile.gif

I don&#39;t know what you&#39;re talking about Dan. It&#39;s spelled correctly in the post.

Also, there was never any such thing as Soviet Revisionism.

Sorry about misspelling your name. http://www.rtsoft.com/iB_html/non-cgi/emoticons/laugh.gif

jjohn
06-28-2003, 08:42 PM
On daisypark, I&#39;ve reduced the black cat penalty from the highly punitive 1/3 to merely painful 1/5. Having gotten socked by the Black Cat a few times, I believe the losing more luck that is granted from getting the daily high score bonus is too grim. http://www.rtsoft.com/iB_html/non-cgi/emoticons/love.gif

07-02-2003, 09:40 AM
I like chocolate http://www.rtsoft.com/iB_html/non-cgi/emoticons/biggrin.gif