Onox Posted June 12, 2019 Share Posted June 12, 2019 Hi I’m back to play Baldur’s Gate after a very long break, and I started learning WeiDU to create installers for a couple of items and spells I created or modified with DLTCEP a few years ago. My first installer worked, but I have a question : the new item I created is chan22.itm. I simply had a look at what chan__ items already existed, and picked the next available number, 22. But if I installed my mod after another one that also added this item, it would override it… so I was wondering whether WeiDU can be made to choose the next available number automatically ? This the COPY part of my improved_white_dragon_scale.tp2 file : // Add the item to the game COPY ~improved_white_dragon_scale/chan22.itm~ ~override/chan22.itm~ SAY NAME1 #6677 // unidentified name SAY NAME2 @1 // identified name SAY UNIDENTIFIED_DESC #6679 SAY DESC @2 Is there a way to tell WeiDU to check what chan__.itm files already exist, and choose the (biggest number already in use + 1) for the file name that it copies inside the override folder, instead of hardcoding 22 ? Thank you Quote Link to comment
Jarno Mikkola Posted June 12, 2019 Share Posted June 12, 2019 16 minutes ago, Onox said: Is there a way to tell WeiDU to ch Even if there were... it's better idea to request a file prefix from the community and use that prefix for all your files. Quote Link to comment
DavidW Posted June 12, 2019 Share Posted June 12, 2019 WEIDU can do that, certainly - but accepted best practice is instead to give your items a (more or less) guaranteed unique name by choosing a ‘modder prefix’ that your files start with. E.g. all new files I create in my mods start with ‘dw’. There is a prefix registration page somewhere (I don’t have the link handy, sorry). Incidentally, the engine doesn’t care whether a suit of chainmail starts with ‘chan’. Quote Link to comment
Jarno Mikkola Posted June 12, 2019 Share Posted June 12, 2019 Slash, slash, slash. Quote Link to comment
Onox Posted June 12, 2019 Author Share Posted June 12, 2019 Thanks a lot for the answers ! 48 minutes ago, DavidW said: WEIDU can do that, certainly - but accepted best practice is instead to give your items a (more or less) guaranteed unique name by choosing a ‘modder prefix’ that your files start with. E.g. all new files I create in my mods start with ‘dw’. There is a prefix registration page somewhere (I don’t have the link handy, sorry). Incidentally, the engine doesn’t care whether a suit of chainmail starts with ‘chan’. Okay, so, I can actually choose any name for my file, and only the item type and stats matter ? I will test it tomorrow ! I wasn’t really planning to share those little mods (except perhaps an item that could be interesting ?) Nevertheless, it’s good to know that this “modder prefix” system was set up I’d still be interested to know how to do that, out of curiosity. If it’s not too complicated. I already had a look at some parts of the documentation for WeiDU, but I started with a simple tutorial because the doc is a little overwhelming. It’s nice to see that you are still here, Jarno. I remember you Quote Link to comment
DavidW Posted June 13, 2019 Share Posted June 13, 2019 It depends on what counts as 'too complicated'. Here's a function (not tested) that does it, but you'd need enough WEIDU (or general programming) experience to be comfortable with functions (and with recursion, if you want to understand how the function works). DEFINE_ACTION_FUNCTION find_unique_name INT_VAR try_next=1 STR_VAR prefix="" ext="" RET name BEGIN ACTION_IF FILE_EXISTS_IN_GAME "%prefix%%try_next%.%ext%" BEGIN OUTER_SET try_next +=1 LAF find_unique_name INT_VAR try_next STR_VAR prefix ext RET name END END ELSE BEGIN OUTER_SPRINT name "%prefix%%try_next%.%ext%" END END Quote Link to comment
Onox Posted June 14, 2019 Author Share Posted June 14, 2019 On 6/13/2019 at 3:13 AM, DavidW said: It depends on what counts as 'too complicated'. Here's a function (not tested) that does it, but you'd need enough WEIDU (or general programming) experience to be comfortable with functions (and with recursion, if you want to understand how the function works). DEFINE_ACTION_FUNCTION find_unique_name INT_VAR try_next=1 STR_VAR prefix="" ext="" RET name BEGIN ACTION_IF FILE_EXISTS_IN_GAME "%prefix%%try_next%.%ext%" BEGIN OUTER_SET try_next +=1 LAF find_unique_name INT_VAR try_next STR_VAR prefix ext RET name END END ELSE BEGIN OUTER_SPRINT name "%prefix%%try_next%.%ext%" END END Thank you so much ! Yes, I have some programming experience and I understand the general idea of your function, although if we do it this way, I would rather have expected a FOR loop instead of a recursive function, but after a look at the documentation, I get the impression that loops in WeiDU are different than in other programming languages I’d like to ask a question about the COPY action to make sure my understanding is correct. I understood what the SAY do, but is it COPY itself that automatically gets a new strref at the end of the dialog.tlk file if we give a new string as the second argument of SAY ? It seems that the documentation doesn’t tell this explicitly, or I have missed it Quote Link to comment
Mike1072 Posted June 14, 2019 Share Posted June 14, 2019 You could do it with a for loop. (You'd use OUTER_FOR.) The SAY command is what's adding strings to dialog.tlk, not COPY. Quote Link to comment
Onox Posted June 14, 2019 Author Share Posted June 14, 2019 (edited) 29 minutes ago, Mike1072 said: You could do it with a for loop. (You'd use OUTER_FOR.) The SAY command is what's adding strings to dialog.tlk, not COPY. Ah, thank you, I had only seen FOR and missed OUTER_FOR ! Ok, so SAY first gets a new string reference if we need one, and then writes the strref inside the itm file (the documentation only says "The string-ref associated with String is written at offset.") ? That makes more sense Edited June 14, 2019 by Onox Quote Link to comment
DavidW Posted June 15, 2019 Share Posted June 15, 2019 You can do imperative-style loops in WEIDU if you like, and most people do. I just like recursion. Quote Link to comment
Onox Posted June 15, 2019 Author Share Posted June 15, 2019 1 hour ago, DavidW said: You can do imperative-style loops in WEIDU if you like, and most people do. I just like recursion. I agree that recursion is nice Your function works ! I just had a little trouble passing the arguments at first, and another problem is that the items are numbered starting with 01, not 1, so I had to add an extra step : DEFINE_ACTION_FUNCTION find_unique_name INT_VAR try_next=1 STR_VAR prefix="" ext="" RET name BEGIN PRINT "find_unique_name arguments : %prefix%, %try_next%, %ext%" // Items are actually numbered starting with 01 and not 1 : ACTION_IF try_next < 10 THEN BEGIN OUTER_TEXT_SPRINT s_try_next "0%try_next%" // OUTER_SET s_try_next = "0%try_next%" does not work here : « ERROR: cannot convert 0%try_next% or %0%try_next%% to an integer » (why?) END ELSE BEGIN OUTER_SET s_try_next = try_next END ACTION_IF FILE_EXISTS_IN_GAME "%prefix%%s_try_next%.%ext%" BEGIN OUTER_SET try_next +=1 LAF find_unique_name INT_VAR try_next STR_VAR prefix ext RET name END END ELSE BEGIN OUTER_TEXT_SPRINT name "%prefix%%try_next%.%ext%" END END LAUNCH_ACTION_FUNCTION find_unique_name STR_VAR prefix = "chan" ext = "itm" RET name END PRINT "returned value : %name%" I realise now that it’s a little silly and brittle to do it like this, especially when uninstalling, but I just wanted to train a little with the syntax and see if I could make it work. I will use unique names with a prefix like you advised me Now, I’ll try to make an install script for a spell. And after that, I have another item where I needed to add a projectile. I didn’t know how to do that with DLTCEP and I stopped at that point three years ago… I might have to ask another question then Thank you all for your answers ! Quote Link to comment
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.