ES Guides tutorial question

NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Locked
Tristan de Inés

ES Guides tutorial question

Post by Tristan de Inés »

Going through the usecode for dummies tutorial (adding an NPC and usecode for it), I can't get the usecode to work and I don't see whats wrong.

-The usecode function number is the same as the NPC function number
-the usecode is the same as in example 2b3
-the usecode.uc is in the patch folder of bg
-I compiled usecode.uc using ucc.exe and renamed "usecode.uco" into "usecode"
-"usecode" is in the patch folder
-I started a new game

Well, there's Bob in the middle of the pub, dancing happily, but he doesn't say a word.
Trying the conversation tutorial with the doubleclick event doesn't work either.
Tristan de Inés

Re: ES Guides tutorial question

Post by Tristan de Inés »

Using latest snapshots of Exult and ExultStudio.
Tristan de Inés

Re: ES Guides tutorial question

Post by Tristan de Inés »

nevermind... I didn't have the right "patch" directory set in exult.cfg

This is fun... usecode rocks! ;)
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by marzo »

A good way to learn usecode is to see what others have done. I recommend that after the tutorials, you check out Alun Bestor's Quests and Iteractions mod and my SI Fixes.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Tristan de Inés

Re: ES Guides tutorial question

Post by Tristan de Inés »

I just decompiled BG's usecode and ran Tawns Visual Basic tool over it, to make it more readable (nice work there, by the way). I'm hoping to find out what the intrinsics are and how they can be effectively used.

Or is there already an intrinsic list with descriptions somewhere?
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by marzo »

It is my tool actually, but nevermind :-) Most of the documentation of the intrinsics are in the Exult source, but there was someone (Pertex IIRC) writting documentation for it; I think there is a homepage, but I can't find the URL anywhere.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by marzo »

And before I forget: there are some parts of the usecode (both BG's and SI's) which are horribly mangled by the tool. I haven't yet have time to figure out what is causing it... but I intend to fix it when I do. Usually, these places can be spotted easily, but I've run accross some usecode functions which had very subtle errors :-(
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Tristan de Inés

Re: ES Guides tutorial question

Post by Tristan de Inés »

> It is my tool actually, but nevermind

Oops, sorry! Anyways, nice work. Would you put the code to your tool online sometime? If I'm really bored once, I just might reimplement it in Java, to make it available to non-windows users, and perhaps perform some meaningful function-renaming while I'm at it.


Another thing I wanted to ask, what happens if you include an existing function in a patch-usecode? Is the old function overwritten or is the new function ignored?
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by marzo »

The old function is ignored, while the new one runs. You can still access the old function, though, if you need it; use "function_name.original();" for that.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by artaxerxes »

I have another question regarding the usecode tutorials and ucc:

I created a usecode egg that triggers when you approached a standing NPC. The NPC usecode is 0x401, so that's what I put in the egg. The usecode function itself contains the following code:
#include "ucdefs.h"

const int MONK = 1;

monk_dialogue 0x401 ()
{
var given = 0;
if(event == 0)
return;
if(event == 1){
item.say("The monk seems to ignore you");
item.hide();
return;
}
if(event == 3)
{
MONK.say("A cloaked individual stands still and silent, while a muffled voice comes from a cauldron. @Do you need help?@");
converse ([ "Bye", "Heal", "Uncurse","Donate"])
{
case "Bye":
say("@Keep safe.@");
break;
case "Heal" (remove):
say("@You have been healed!@");
case "Uncurse" (remove):
say("@You have been uncursed!@");
case "Donate" (remove):
given = given + 1;
say("@Thank you!@");
if(given == 5)
{
say("@You are blessed!@");
} else {
add("Donate");
}
}
MONK.hide();
}
}


If I replace "MONK" by "item", the function stops working. That is, if the function is called by the usecode egg, I have no access to the item variable. Is it me who does something wrong or am I missing something?

thx
Artaxerxes
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by marzo »

If you define MONK = -1 instead it will work; the usecode number of NPCs must is negative. As a general rule, the NPC's number in usecode is the negative of what you see in Exult Studio (or in the Cheat Screen). The exception is the Avatar, whose usecode id is -356.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
SB-X
Posts: 980
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by SB-X »

The behavor is correct isn't it? If it's called by the egg, then that's the item.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by marzo »

Yes, I forgot to say that. Actually, it seems that I have misunderstood Artaxerxes' question entirely :-) When the egg calls an usecode function, the egg is the 'item'; and since the egg cannot be translated to an NPC, it can't say anything, which is why the monk would not say anything.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: ES Guides tutorial question

Post by artaxerxes »

now this makes sense. Thx

Artaxerxes
Locked