ucc problems

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
mjohnston
Posts: 58
Joined: Thu May 14, 2020 1:34 pm

ucc problems

Post by mjohnston »

I decided to finally mess around with some usecode for an NPC, but I'm having trouble compiling... in exult I get an error message that says something like "error executing usecode compiler ('ucc')". I was was getting this message with a version of the tools that I downloaded a couple months ago, so today I downloaded the latest snapshots of tools, exult, and studio and still get the same thing.

somewhere with something I downloaded I found a description of creating a basic conversational NPC (by wizardry dragon I think, may have been packed in with the Fuedal Lands mod) which had a directions for compiling usecode from the command line (I think) - said to install the tools in the ultima7 patch directory (did that, but does it want the actuall tools in that directory, or the folder 'tools' that the tools end up in when installed to be in that directory... ie, tools in their own folder in the patch dir, or just in the patch dir with everything else? I tried both and get the same message when trying to compile through the 'compile' option in studio)

when I to compile it from the command/run line the way the doc says it has a window that flashes for a second and goes away... sometimes it says something (depending on what random thing I tried) but the window is never up long enough to read it.

if I just double click on the ucc.exe it opens up that window, but then what do I do with it? sorry, I'm not so good with programs that don't have readily available and easy to understand directions... but can someone please help, or point me in some direction?
thanks, confused-matthew
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

UCC doesn't need to be in any specific place. It is a self contained program. It should be in the same folder that the file you are compiling is for ease of use.

Put

#game "blackgate"

or

#game "serpentisle"

at the top of the file you are making to designate the game you are compiling for. You probably want to include

#autonumber 0xA00

at the top so it won't override function from the original.


If you are using Windows, you should use the program "command prompt" located in the accessories folder. The you need to type cd\Whatever directory UCC is in

ucc -o usecode Usecode.uc

"Usecode.uc" would be the name of the file you made.
mjohnston
Posts: 58
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by mjohnston »

thanks, got it to compile and I now have my first NPC that is actually conversational... now going to try messing around with other usecode stuff :)
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by drcode »

Cool. Keep in mind that if you find bugs in ucc, or things you might like added, you can suggest them here.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

Well Marzo could update it with the new intrinsics he just found :p. (no rush)

I went to give Armageddon a try and realized it wasn't updated. Good job finding more intrinsics. I thought that I was going to have to replace Wizard eye and Armageddon until recently.

I noticed the recent change for virtue stones default map settings even in SI. Do you think that the intrinsic exists in SI? The best I can do with the coding right now is have the default runestone positions and overwrite one position via save_pos() and use UI_teleport_to_saved_pos(AVATAR). I works pretty well although if it got used during the plot of SI, it could cause bugs.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

I noticed the recent change for virtue stones default map settings even in SI. Do you think that the intrinsic exists in SI?
Doesn't seem to; save_pos and teleport_to_saved_pos intrinsics occupy the slots where the virtue stone intrinsics 'should' be located. You could try using static vars instead, or maybe I could make the intrinsics available for SI (although many plot items in SI are in the virtue stone class and could cause trouble).

As for updating UCC: the next version of the tools should already have it; but updating them is Kirben's department, so you'll have to bug him if they were not updated.
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

maybe I could make the intrinsics available for SI (although many plot items in SI are in the virtue stone class and could cause trouble).

Could this be avoided by making another class "Virtue Stone SI" and having UI_mark_virtue_stone_SI(object obj) and UI_recall_virtue_stone_SI(object obj)? That would mean updating UCC, Exult, and ES though.


You could try using static vars instead.

I have no idea how the mark intrinsic stores different coordinates. This is what I have right now. Sorry I haven't cleaned up the coding to make it easier for others to read yet.



Mark ()
{
var var0000;
var var0001;
var var0002;
var var0003;

if (!(event == 0x0001)) goto labelFunc0662_00B0;
UI_halt_scheduled(item);
var0000 = UI_click_on_item();
if (!(!(UI_get_item_shape(var0000) == 1316))) goto labelFunc0662_0026;
goto labelFunc0662_009A;
labelFunc0662_0026:
if (!UI_get_barge(0xFE9C)) goto labelFunc0662_0033;
goto labelFunc0662_009A;
labelFunc0662_0033:
UI_item_say(item, "@Kal Por Ylem@");
var0001 = UI_execute_usecode_array(var0000, [0x23, 0x55, 0x0612]);
var0002 = UI_execute_usecode_array(item, [0x58, 0x0043, 0x6F, 0x70, 0x6A]);
var0001 = UI_get_object_position(item);
UI_sprite_effect(0x000D, var0001[0x0001], var0001[0x0002], 0x0000, 0x0000, 0x0000, 0xFFFF);
save_pos();
UI_set_item_quality(var0000, 1);
goto labelFunc0662_00B0;
labelFunc0662_009A:
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A, 0x55, 0x0606]);
labelFunc0662_00B0:
return;
}


Recall ()
{
var var0000;
var var0001;
var var0002;
var var0003;

if (!(event == 0x0001)) goto labelFunc0664_00B0;
UI_halt_scheduled(item);
var0000 = UI_click_on_item();
var0001 = UI_get_object_position(item);
UI_item_say(item, "@Kal Ort Por@");
if (!(UI_get_item_shape(var0000) == 1316)) goto labelFunc0664_009A;
if (UI_get_item_quality(var0000) == 1)
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_teleport_to_saved_pos(AVATAR);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 0))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([1447, 1386, 3, 1]);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 1))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([488, 2698, 0, 1]);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 2))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([2680, 1162, 0, 1]);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 3))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([2327, 970, 3, 1]);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 4))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([728, 122, 0, 1]);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 5))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([839, 2554, 0, 1]);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 6))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([936, 1173, 0, 1]);
}
else if ((UI_get_item_quality(var0000) == 0) && (UI_get_item_frame(var0000) == 7))
{
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A]);
var0002 = UI_delayed_execute_usecode_array(var0000, [0x23, 0x55, 0x0613], 0x0006);
UI_sprite_effect(0x0007, var0000[0x0002], var0000[0x0003], 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_obj_sprite_effect(item, 0x0007, 0xFFFE, 0xFFFE, 0x0000, 0x0000, 0x0000, 0xFFFF);
UI_add_cont_items(AVATAR, 1, 1316, UI_get_item_quality(var0000), UI_get_item_frame(var0000));
UI_remove_item(var0000);
PARTY->move_object([825, 1443, 0, 1]);
}
goto labelFunc0664_00B0;
labelFunc0664_009A:
var0002 = UI_execute_usecode_array(item, [0x6F, 0x70, 0x6A, 0x55, 0x0606]);
labelFunc0664_00B0:
return;
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

Actually after going through the SI usecode, I only found the save_pos and teleport_to_saved_pos intrinsics used for the Amulet of Balance to mark which Serpent Gate you used. So those intrinsics shouldn't cause a problem unless used in Silver Seed add-on itself since the only function that calls it is itself or if used in a similar place that the player is supposed to work their way out ie. Gorlab Swamps, Mountains of Freedom, etc. where any teleportation would screw things up.

Serpent rune (shape 330) seems to be the only Virtue Stone class item. I don't even think they have anything to do with teleportation. They seem to have triggers from flags, frame they are, and where they are placed (based on a brief look at the code and basic observations of the game).

I doubt that adding the mark/recall intrinsics would cause problems if people use a new shape for it instead of the existing one. It is also doubtful whether it would even cause problems with existing items.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

How do I have someone other than the Avatar select conversation choices?
This is how I get it to converse with the Avatar (really simplified version for what I will have). What is inside the parenthesis of converse doesn't seem to do anything.

add(["Awaken", "Glimmer"]);

converse (0)
{
case "Awaken":
{
script caster
{
call 0x648, DOUBLECLICK;
}
abort;
}
case "Glimmer":
{
script caster
{
call Glimmer, DOUBLECLICK;
}
}
abort;
}

I think it would be a bit confusing showing the Avatar talking when another party member is using the spell book.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

You can't, only the avatar gets to pick choices. Re: the parenthesis of converse: I will be checking it, it *should* do something.
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

An old tutorial doesn't even list the parenthesis. The compiler requires some value there although I haven't noticed any differences between any of the values I had tested.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

usecode/compiler/*: Added do-while support for UCC. Renamed return opcodes to make them more intuitive. Added support for 32-bit function IDs, string offsets and integers. 32-bit jump offsets are NOT implemented yet.

My source file for the spellbook function will be about 200k for each book quality (each quality can be placed in a separate function) and that is the smallest that I can split the code into. With these changes do you think that UCC can support it? (I am still writing out the conversation branches so I can't test it for awhile.) I don't know what jump offsets are so I have no idea what effect not having support for them would have.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

The important part will be the string offsets. You can very likely do the entire book code in one function now, as long as all strings together do not exceed around 2 billion characters or so.
------
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]
drcode
Site Admin
Posts: 2267
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by drcode »

The expression inside the parentheses is for adding a list of answers, so I think you could have put the ["Awaken", "Glimmer"] there.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

"UI_lightning ()" seems to have broken within the past couple patches.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

"UI_lightning ()" seems to have broken within the past couple patches.
That seems unlikely as its code hasn't been changed in quite a while; what do you mean exactly by "broken"?
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

It compiles but doesn't work at all (no flash or sfx) in the latest version of Exult. I put the same code in an older version of Exult and it works fine so it isn't the compiler. I think it became a problem somewhere between the latest version of Exult and the 2007-06-03. I actually haven't tested in BG yet only SI.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

I can't even compile the spellbook function properly with less than 250,000 characters completely. It allows me to access up to 6th level spells. After that the conversation branches just close the book. I can put a previous level into comments and then the next level on the list works properly.

I included only the files that were needed for the spellbook and it compiled to about 63k.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

Hm. Can you send these files to my e-mail so I can take a look?
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

AOL mail server and another one reject my e-mails saying they had the Bagel virus (well AOL just said there was an error). My admittedly out of date antivirus doesn't detect anything.

I will try sending you an e-mail without an attachment to see if I can send any mail at all. Do you know of a freeware or opensource virus program without any spyware that gets installed with it?
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

If you use Windows, you can try AVG.
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

It didn't find anything in that folder. I will run a full system scan after I send this. While I was waiting for your reply, I checked all my files in the archive with context showing all characters and didn't notice anything unusual.

I wonder if the server/s are detecting one or more of my files as a virus because of UCC scripts or intrinsics. It could just be a mail server issue.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

Here is the archive if you would like to look at it. I really doubt there is a virus, but I would understand if you won't download it.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

There is only the problem that there aren't any available servers for me to download from. Hrm. Can't you attach it to an e-mail message to me? I did get your earlier message, even if you didn't get my reply.
------
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: ucc problems

Post by SB-X »

I could download that file just fine. Need me to forward it to you or do you already have it now?
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

Geez. Now it lets me send the file fine. E-mail server must have be screwy and kept false detecting my file as a virus or something.


There is only the problem that there aren't any available servers for me to download from.

You have that problem with filefront too? You really need to find me a good download site that works well with Brazil.
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

Sorry for the double post, but I realized that it might have been Norton Antivirus that was false detecting it as a virus and screwing up my mail sending. I had it off when I sent the file this time. I don't think I tried sending it with Norton disable before now.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

You have that problem with filefront too?
Apparently so :-(

SB-X: If Malignat Manor's message doesn't arrive, I will be taking you up on that offer.
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

Did it arrive? It told me it sent the file this time.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

It came through.

[Marzo takes a look at Spellbook.uc]

*a high pitched shriek pierces the internet*

[Marzo's sanity is irrevocably destroyed at the sheer horror]

Ack. Ack. Ack. Please forgive me for being so blunt, but it is horrible!

*shudders*

I am going to have nightmares about it for quite a while...

Well, at least I know what the problem is; which means that congratulations are in order, you just proved me wrong.

You see, the problem is that UCC is limited by 16-bit jump offsets. What that means is that, after converting to byte-code, it can't jump by more than 32767 bytes in any direction in one go. I hadn't implemented 32-bit jump offsets in UCC because I thought no one would *EVER* need it. But I was assuming that the usecoder would use such things as modularization of usecode. I never even considered the possibility that someone would be making an unreadable, unmaintainable, huge function which is basically copy & paste all over.

I will give a few hints about usecode to help along your own sanity in future days; when you spend more than a few days away from your usecode and come back to fix a bug, you will either thank whatever deity you worship for listening to this advice or curse the day you chose to disregard it. Trust me.

So here it goes:


1) Indentation helps. A lot. Since UCC (like most decent compilers) ignores white space (tabs, spaces, enters), you can use it at will to format usecode into a layout which helps you quickly spot blocks of code. Compare the difference:

Code: Select all

if (gflags[WIZARD_MODE] == true)
{
script caster
{
call Douse, DOUBLECLICK;
}
abort;
}
else if ((UI_get_npc_prop(caster, MANA) >= mana0) && (UI_get_npc_prop(caster, EXPERIENCE) >= level0))
{
UI_set_npc_prop(caster, MANA, - mana0);
script caster
{
call Douse, DOUBLECLICK;
}
abort;
}
else if (!(UI_get_npc_prop(caster, EXPERIENCE) >= level0))
{
if (UI_get_random(100) >= 50)
{
caster_face.say("More skill in molding the ether is required before such an attempt can be made");
abort;
}
else if (UI_get_random(100) >= 2)
{
caster_face.say("Perhaps in time this level of skill will be achived");
abort;
}
else
{
caster_face.say("Psst, global flag 1600 activates the wizardry mode for this spellbook");
abort;
}
}
else if (!(UI_get_npc_prop(caster, MANA) >= mana0))
{
if (UI_get_random(100) >= 50)
{
caster_face.say("More spiritual energy must be aquired before accessing into the ether");
abort;
}
else if (UI_get_random(100) >= 2)
{
caster_face.say("I believe we need to rest before I can attempt that");
abort;
}
else
{
caster_face.say("Psst, global flag 1600 activates the wizardry mode for this spellbook");
abort;
}
}
else
{
UI_flash_mouse(CURSOR_X);
abort;
}

Code: Select all

if (gflags[WIZARD_MODE] == true)
{
	script caster
	{
		call Douse, DOUBLECLICK;
	}
	abort;
}
else if ((UI_get_npc_prop(caster, MANA) >= mana0) && (UI_get_npc_prop(caster, EXPERIENCE) >= level0))
{
	UI_set_npc_prop(caster, MANA, - mana0);
	script caster
	{
		call Douse, DOUBLECLICK;
	}
	abort;
}
else if (!(UI_get_npc_prop(caster, EXPERIENCE) >= level0))
{
	if (UI_get_random(100) >= 50)
	{
		caster_face.say("More skill in molding the ether is required before such an attempt can be made");
		abort;
	}
	else if (UI_get_random(100) >= 2)
	{
		caster_face.say("Perhaps in time this level of skill will be achived");
		abort;
	}
	else
	{
		caster_face.say("Psst, global flag 1600 activates the wizardry mode for this spellbook");
		abort;
	}
}
else if (!(UI_get_npc_prop(caster, MANA) >= mana0))
{
	if (UI_get_random(100) >= 50)
	{
		caster_face.say("More spiritual energy must be aquired before accessing into the ether");
		abort;
	}
	else if (UI_get_random(100) >= 2)
	{
		caster_face.say("I believe we need to rest before I can attempt that");
		abort;
	}
	else
	{
		caster_face.say("Psst, global flag 1600 activates the wizardry mode for this spellbook");
		abort;
	}
}
else
{
	UI_flash_mouse(CURSOR_X);
	abort;
}
Both, BTW, are the same pieces of code extracted from Spellbook.uc. The difference is that the latter indents everything between braces by exactly 1 tab for each pair of braces surrounding the code block. You can use whatever you prefer -- some people prefer to use spaces instead of tabs; but in any case, readability is vastly improved. The link I gave above has a lot of information about different indentation styles.


2) Modularize. If there is something which you do over and over again, put that thing in a function of its own and call it instead. The less duplicate code you have, the easier will it be to change the way things work without having to do the same thing again and again 200 times. I will give an example below.


3) Arrays are your friends. For example: instead of

Code: Select all

mana0 = 1;
mana1 = 2;
mana2 = 3;
mana3 = 4;
mana4 = 6;
mana5 = 7;
mana6 = 8;
mana7 = 10;
mana8 = 11;
you could have

Code: Select all

mana = [1, 2, 3, 4, 6, 7, 8, 10, 11];
and likewise for level0, level1, etc. Then, instead of having to repeat the following code 200 times:

Code: Select all

else if ((UI_get_npc_prop(caster, MANA) >= mana0) && (UI_get_npc_prop(caster, EXPERIENCE) >= level0))
{
	UI_set_npc_prop(caster, MANA, - mana0);
	script caster
	{	call 0x648, DOUBLECLICK;	}
	abort;
}
plus variations for mana1, mana2, etc., you could do something like this *once*:

Code: Select all

else if ((UI_get_npc_prop(caster, MANA) >= mana[circle+1]) && (UI_get_npc_prop(caster, EXPERIENCE) >= level[circle+1]))
{
	UI_set_npc_prop(caster, MANA, - mana[circle+1]);
	script caster
	{	call function, DOUBLECLICK;	}
	abort;
}
where 'circle' and 'function' are variables set when you select the spell; e.g.,

Code: Select all

[...]
case "Awaken":
	function = 0x648;
	circle = 0;
	break;
case "Douse":
	function = &Douse;
	circle = 0;
	break;
[...]
You could also use a function (not intrinsic) from BG/SI ("chooseFromMenu" -- which if I am not mistaken, it is function 0x956 in SI -- or "chooseFromMenu2" which is 0x957 in SI) to prompt a menu with choices for the player which he must select from. The first returns the actual choice, while the latter returns the index (1-n) of the choice.


4) There is no need to surround strings in anything other than double-quotes. Thus, for example:

Code: Select all

add([("Linear"), ("First"), ("Second"), ("Third"), ("Fourth"),
("Fifth"), ("Sixth"), ("Seventh"), ("Eighth"), ("Class skills"), ("Close book")]);
is exactly like

Code: Select all

add(["Linear", "First", "Second", "Third", "Fourth",
"Fifth", "Sixth", "Seventh", "Eighth", "Class skills", "Close book"]);
This is a minor nit, but still...

5) Like arrays, loops can be life savers. Consider this:

Code: Select all

if (!((gflags[AWAKEN] == false) && (gflags[WIZARD_MODE] == false)))
	add("Awaken");
if (!((gflags[DOUSE] == false) && (gflags[WIZARD_MODE] == false)))
	add("Douse");
if (!((gflags[FIREWORKS] == false) && (gflags[WIZARD_MODE] == false)))
	add("Fireworks");
if (!((gflags[GLIMMER] == false) && (gflags[WIZARD_MODE] == false)))
	add("Glimmer");
if (!((gflags[HELP] == false) && (gflags[WIZARD_MODE] == false)))
	add("Help");
if (!((gflags[IGNITE] == false) && (gflags[WIZARD_MODE] == false)))
	add("Ignite");
if (!((gflags[THUNDER] == false) && (gflags[WIZARD_MODE] == false)))
	add("Thunder");
if (!((gflags[WEATHER] == false) && (gflags[WIZARD_MODE] == false)))
	add("Weather");
add("Choose another spell");
Now compare (assuming AWAKEN is the smallest number, WEATHER the largest and that they are all sequential):

Code: Select all

var spells = ["Awaken", "Douse", "Fireworks", "Glimmer", "Help", "Ignite", "Thunder", "Weather"];
for (choice in spells with index)
{
	if (gflags[WIZARD_MODE] || gflags[AWAKEN + index - 1])
		add(choice);
}
Much easier, right? I also changed the condition to avoid UCXT-esque double-negatives and used OR conjunction (the '||') instead of AND (the '&&'). The 'for' loop goes through the elements of an array you specify, and you can give names to the elements of that array and the index of that element.


Those are all that I have to say for now.

Man, I really need to write that usecode tutorial ASAP.
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

Well right now, no offense, your tutorial has bare bones basics and leaves out so much stuff. It seems more oriented towards people who already know how to code. I indent the major stuff, but not alot of things, which is harder for other people to read.

With the replace feature, most mass reproduced stuff isn't that hard to change. It would have been so much easier to code the book if I knew what to do beforehand. I'm working on changing it, but I'm not even going to be sure if all I do is right until I'm finished.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

Well right now, no offense, your tutorial has bare bones basics and leaves out so much stuf
None taken, as it is not really a tutorial but some formatting guidelines with a few bits of UCC thrown in.
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

"UI_stop_time()" doesn't work anymore either in SI at least. In an older versions of Exult it works fine. It worked until recently like "UI_lightning ()". Do you have any clues yet as to which change caused this to happened?
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

After some testing, they both work in BG but not SI. I'm guessing that this update shown below is when the problem started. It could just be a problem, because UCC isn't updated yet to reflect changes and Exult is.


2007-06-07 Marzo Sette Torres Junior
* Fixed bug where nearby animations could temporarily stop if an "abort"
took place during a conversation.
* More intrinsics uncovered with rip/wud/wuc:
BG: intrinsic 0x92 is *set_camera*, not center_view.
intrinsic 0x94 centers the screen around a (x, y) coordinate;
it has been renamed view_tile.
SI: intrinsic 0x19 is *get_item_weight*, not get_item_usability.
intrinsic 0x67 is definitelly remove_all_spells.
**** intrinsic 0x6b is stop_time. ****
intrinsic 0x70 is armageddon (yes, it is there).
**** intrinsic 0x72 is lightning. ****
intrinsic 0xb0 is view_tile.
Old center_view intrinsic is still available for both BG and SI.
Also, set_camera intrinsic also centers on objects, not just actors
SI intrinsics remove_all_spells, get_item_weight and get_skin_colour
were made available for BG too.
* Updated/fixed a couple errors in intrinsic documentation.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

They both work perfectly fine for me here. Try this: create a text file with the following contents:

Code: Select all

#game "serpentisle"

Bolt shape#(0x2d3) ()
{
	UI_stop_time(2000);
}
Name it "test.uc" and place it in an easy-to-reach directory and put a copy of UCC there too (if it is not in your system's PATH). Then open a DOS prompt (e.g., Start menu->Run->cmd.exe) and change to that dir. For example, if you placed the file in D:\Temp, you would type

Code: Select all

D:
cd Temp
pressing enter after each line. Then type

Code: Select all

ucc -o test test.uc
and press enter. If the compiler prints a message similar to the following:

Code: Select all

test.uc:5: 'UI_stop_time' not declared
then Kirben hasn't updated it and you should ask him to do so.
------
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]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by Malignant Manor »

I have no trouble compiling it. It just doesn't work in SI anymore. It was available as an intrinsic in SI before along with UI_lightning(). I figured when you discovered the intrinsics in SI, that you changed Exult to read the intrinsics that you discovered instead of the ones that were previously used.

I don't see how you can get them to work "ingame" anymore as in actually do something other than compile, if you are using the compiler that is available right now. If you didn't change Exult to use the new found intrinsics instead of the ones it previously used to do that function, then I have no idea why the heck it wouldn't work.

It worked before. It doesn''t now.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by marzo »

I have no trouble compiling it. It just doesn't work in SI anymore.
Ah, I think I know what is going on. It is indeed the version of the usecode compiler that is available: it is compiling the using old intrinsic table, before the updates I made. The makefile used did not list the compiler as depending on the intrinsic tables, so it did not know to update the compiler. I've fixed the makefile, so that the next version of the compiler will use the correct tables.
------
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]
tw

Re: ucc problems

Post by tw »

i have ultima collection and have installed it but i cannot get ultima 7 to run at all and have no idea how to run it through windows or exult
artaxerxes
Site Admin
Posts: 1310
Joined: Thu May 14, 2020 1:34 pm

Re: ucc problems

Post by artaxerxes »

for what it's worth, Si-french uses 32bit usecode as the usecode function that holds most of the books swells tremendously when translated in french and goes well beyond the capabilities of 16 bit.

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

Re: ucc problems

Post by marzo »

I will take a look at the SI-french usecode, but I'd guess that it only uses 32-bit string offsets, not 32-bit jump offsets.
------
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: ucc problems

Post by marzo »

I will take a look at the SI-french usecode, but I'd guess that it only uses 32-bit string offsets, not 32-bit jump offsets.
Now that I have taken a look at SI-French usecode, I can state with certainty that it only uses 32-bit string offsets as I had guessed.
------
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]
Locked