New Tavern Script. Need help.

Discussion forum for Devil Whiskey 3rd Party MODS.

Moderator: Admin

User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

New Tavern Script. Need help.

Post by origen »

I am having some strange effects with my Tavern script. I received some inspiration (as well as some code snippets :D ) from HGamer, but it is not always acting like I think it should.

So, what is the problem? When I enter the tavern, and order a drink, I get the message "Who will drink" Here is where the problem comes in. If I select a character (in this case F3), it sometimes works (and goes to the next part), while other times it does not work, and gives me a return 1 (which keeps me in the same cell, but the script ends.) This does not happen all the time, but it does happen consistently.

The other issue is that if you order Ale, it does not regenerate BP's, as I would like it to. Well, here is the script...

Code: Select all

#A Generic Tavern in Skara Brae

from eventAPI import showPicture, playSpecAudio, optionInput, tickGame, getPartyCount, isPC, modifyGold, modifyHP, modifySP, modifyBP, giveItems, stopSpecAudio
from APIUtils import showMessage
from SDLKeys import SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_ESCAPE
from SDLKeys import SDLK_r, SDLK_t, SDLK_o, SDLK_a, SDLK_b, SDLK_m, SDLK_f, SDLK_g, SDLK_n, SDLK_y

def fireEvent(e):
    showPicture(e, "Tavern")
    playSpecAudio(e, "Tavern")
    choice = optionInput(e, ["Welcome to Skull Tavern!", "What will be your pleasure", "", "(O)rder a Drink", "(T)alk to Barkeep", "(R)ent a Room"], ["(ESCAPE) to Exit"], [SDLK_o, SDLK_t, SDLK_r, SDLK_ESCAPE])
    if (choice == SDLK_r):
        rentaroom(e)
    elif (choice == SDLK_t):
        talk(e)
    elif (choice == SDLK_o):
        maindrink(e)
    elif (choice == SDLK_ESCAPE):
        return 0
    else:
        showMessage(e, ["\"I do not understand your jibberish!\""])
        mainmenu(e)


def mainmenu(e):
    showPicture(e, "Tavern")
    playSpecAudio(e, "Tavern")
    choice = optionInput(e, ["Welcome to Skull Tavern!", "What will be your pleasure", "", "(O)rder a Drink", "(T)alk to Barkeep", "(R)ent a Room"], ["(ESCAPE) to Exit"], [SDLK_o, SDLK_t, SDLK_r, SDLK_ESCAPE])
    if (choice == SDLK_r):
        rentaroom(e)
    elif (choice == SDLK_t):
        talk(e)
    elif (choice == SDLK_o):
        maindrink(e)
    elif (choice == SDLK_ESCAPE):
        return 0
    else:
        showMessage(e, ["\"I do not understand your jibberish!\""])
        mainmenu(e)

       
def maindrink(e):
    personlist = [SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_ESCAPE]
    person = optionInput(e, ["\"Who will drink?\""],
        ["(F1-F8) for Character", "(ESCAPE) to Exit"],
        personlist)
    idx = personlist.index(person)
    if (idx == 8):
        showMessage(e, ["\"Come back any time!\""])
        tickGame(e, 4)
        return 0
    elif (idx >= getPartyCount(e)):
        showMessage(e, ["\"What is this, some kind of joke?  There's no one there!\""])
        tickGame(e, 8)
        mainmenu(e)
    elif (not isPC(e, idx)):
        showMessage(e, ["\"We don't serve your kind in here!\""])
        tickGame(e, 8)
        mainmenu(e)
    else:
        choice = optionInput(e, 
           ["Seat thyself.  What shall I get you?",
           "",
           "(A)le",
           "(B)eer",
           "(M)ead",
           "(F)oul Spirits",
           "(G)inger Ale", "",
           "(N)evermind"],[],
           [SDLK_a, SDLK_b, SDLK_m, SDLK_f, SDLK_g, SDLK_n])
        if (choice == SDLK_a):
            if (optionInput(e, ["Such a fine brew will cost you 15 gold.  Will ye pay?"], ["(Y)es, (N)o"], [SDLK_y, SDLK_n]) == SDLK_n):
                nopay(e)
            else:
                if (modifyGold(e, idx, -15)):
                    showMessage(e, ["The ale is weak and flat, but at least it's cheap, right?"])
                    modifyBP(e, idx, 10)
                    mainmenu(e)    
                else:
                    showMessage(e, ["I know not where from you hail, but in these parts we don't give drinks on credit!  Come back when you have the funds!"])
                    mainmenu(e)    
        elif (choice == SDLK_b):
            if (optionInput(e, ["Such a fine brew will cost you 10 gold.  Will ye pay?"], ["(Y)es, (N)o"], [SDLK_y, SDLK_n]) == SDLK_n):
                nopay(e)
            else:
                if (modifyGold(e, idx, -10)):
                    showMessage(e, ["The beer is hardly drinkable, but it sooths your parched throat."])
                    mainmenu(e)
                else:
                    showMessage(e, ["I know not where from you hail, but in these parts we don't give drinks on credit!  Come back when you have the funds!"])
                    mainmenu(e)    
        elif (choice == SDLK_m):
            if (optionInput(e, ["Such a fine brew will cost you 20 gold.  Will ye pay?"], ["(Y)es, (N)o"], [SDLK_y, SDLK_n]) == SDLK_n):
                nopay(e)
            else:
                if (modifyGold(e, idx, -20)):
                    showMessage(e, ["The mead seems to be more water than alcohol, but at least it's drinkable."])
                    mainmenu(e)
                else:
                    showMessage(e, ["I know not where from you hail, but in these parts we don't give drinks on credit!  Come back when you have the funds!"])
                    mainmenu(e)    
        elif (choice == SDLK_f):
            if (optionInput(e, ["Such a fine brew will cost you 50 gold.  Will ye pay?"], ["(Y)es, (N)o"], [SDLK_y, SDLK_n]) == SDLK_n):
                nopay(e)
            else:
                if (modifyGold(e, idx, -50)):
                    showMessage(e, ["You start to feel a little lightheaded."])
                    mainmenu(e)
                else:
                    showMessage(e, ["I know not where from you hail, but in these parts we don't give drinks on credit!  Come back when you have the funds!"])
                    mainmenu(e)    
        elif (choice == SDLK_g):
            if (optionInput(e, ["Such a fine brew will cost you 10 gold.  Will ye pay?"], ["(Y)es, (N)o"], [SDLK_y, SDLK_n]) == SDLK_n):
                nopay(e)
            else:
                if (modifyGold(e, idx, -10)):
                    showMessage(e, ["The ladies in the tavern are not impressed."])
                    mainmenu(e)
                else:
                    showMessage(e, ["I know not where from you hail, but in these parts we don't give drinks on credit!  Come back when you have the funds!"])
                    mainmenu(e)    
        else:
            showMessage(e, ["Another time perhaps?"])
            mainmenu(e)
       


def rentaroom(e):
    if (optionInput(e, ["We have the finest beds in town, for the low cost of 1500 a night.  Will you stay?"], ["(Y)es, (N)o"], [SDLK_y, SDLK_n]) == SDLK_n):
        nostay(e)
    else:
        sleep(e)

def nostay(e):
    showMessage(e, ["Come back if you change your mind."])
    mainmenu(e)

def sleep(e):
    if (modifyGold(e, 0, -1500)):
        showMessage(e, ["You spend about 8 hours in the most comfortable beds you have ever seen.  You awake to find a hearty meal laid out before you.  You haven't felt this good in ages!"])
        tickGame(e, 1920)
        x, c = 0, getPartyCount(e)
        while &#40;x < c&#41;&#58;
            modifyHP&#40;e, x, dice&#40;10, 8, 1&#41;&#41;
            modifySP&#40;e, x, dice&#40;10, 8, 1&#41;&#41;
            x += 1
        return 0
    else&#58;
        showMessage&#40;e, &#91;"You don't seem to have the funds to stay here.  Perhaps you should try a cheaper place?"&#93;&#41;
        mainmenu&#40;e&#41;
Any thoughts?
User avatar
Growler
Necrolord
Posts: 1740
Joined: Mon Feb 14, 2005 10:37 pm
Location: Sputnik
Contact:

Re: New Tavern Script. Need help.

Post by Growler »

origen wrote:I am having some strange effects with my insatiable Tavern-habit. So, what is the problem? *BEEELLCH* When I enter the tavern, and order a drink, then another, & another...I finally get the message "You've had too much to drink!"

This does not happen all the time, but it does happen consistently when I lose count of how many drinks I've *BUURRP* had.

The other issue is that if you order Ale, it taste stale & does not regenerate intelligence or sanity points as I would fain like it to.

Please hold any thoughts 'til I..Oh My--Pardon Me! return...uh-oh...fromtheloo!
OK. :P

(wish I Could offer help or just directions to the nearest medieval AA meeting, but your script looks strikingly like Swahili! :? ..in fact, after looking at it as I do post-modern art, I feel a 12-pk o' stale-ale coming on!)

u sure this script doesn't work just fine & you're just..you know..?? :D
No Contraries : No Progression.
Opposition is true friendship, unless one is opposed to true friendship or (try) Resisting here http://www.cafepress.com/notheresistor
User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

Post by origen »

Well, after further testing, I have come to the conclusion that it's broken.

The entire script works fine the first time I do everything. But, if I leave the tavern, it doesn't work when I re-enter, unless I shut down the game and restart it. Once I select which character to show (F1-F8), it just errors out and returns 1.

Growler,

Are you sure you don't understand the script? This could just be part of the tutorial. :twisted:
Last edited by origen on Tue Apr 05, 2005 6:59 pm, edited 1 time in total.
User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

Post by origen »

Just a possible thought has to do with when the script defines the "idx". Perhaps the script is not resetting this when the script ends, so when I enter another person, it doesn't know what to do? Is there a way to reset this?

But, if it is the first time that I am in the script, I can switch back and forth between characters. So maybe that's not it. But who knows.
User avatar
Growler
Necrolord
Posts: 1740
Joined: Mon Feb 14, 2005 10:37 pm
Location: Sputnik
Contact:

Post by Growler »

Who knows?
Maybe...the Shadow K(night)nows? 8)

As fer this being part of the tutorial, well..I think I get the jest of it! :P

that's about it as evidenced by this: idx=index~?:??*

?:??=confused guy with questionablearrings..
No Contraries : No Progression.
Opposition is true friendship, unless one is opposed to true friendship or (try) Resisting here http://www.cafepress.com/notheresistor
User avatar
HGamer
War Monger
Posts: 188
Joined: Thu Feb 10, 2005 7:59 pm
Location: Land of fruits & nuts, i.e. SoCal
Contact:

Post by HGamer »

All that I can suggest right now is to try simplifying the code a bit by changing the main routine to:

Code: Select all

def fireEvent&#40;e&#41;&#58; 
    mainmenu&#40;e&#41; 
But I like designing my scripts differently than you do, so whatever makes sense to IDLE, Python, the DW engine and yourself.

Looks like you're using that neat .index feature of Python in maindrink, but that's not in the current version of the inn script in my mod. Don't remember why right now. It's been a while. I'm pretty sure it worked properly, though.

Only other thing that I can think of is that there's no place where you actually do a "return 1". I personally like making sure that the return status is defined for all paths that you can take.
1 point 21 jigawatts!
User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

Post by origen »

Well, what I did was define a return 0 at the end of every script path, as HGamer suggested, and it does seem to work now. I did alot of editing from what was originally posted earlier, but the premise is the same.

The reason I do not do the

Code: Select all

def fireEvent&#40;e&#41;&#58;
    mainmenu&#40;e&#41;
as you mention is because with that script, every time it goes back to the main menu (which is a few times in the script), it begins playing the music from the start again, which I didn't like. Of course, in the code I posted, both the fireEvent(e) and mainmenu(e) were exactly the same. I forgot to remove the line where it plays the music.

But, I will do a little more testing now to make sure that it is working properly, and then I can begin restoring BP's as it should, since of course that isn't working at all. :(
User avatar
HGamer
War Monger
Posts: 188
Joined: Thu Feb 10, 2005 7:59 pm
Location: Land of fruits & nuts, i.e. SoCal
Contact:

Post by HGamer »

OK, in that case use:

Code: Select all

def fireEvent&#40;e&#41;&#58; 
    showPicture&#40;e, "Tavern"&#41; 
    playSpecAudio&#40;e, "Tavern"&#41; 
    mainmenu&#40;e&#41; 
and take the "playSpecAudio" line out of mainmenu, so you only start playing the song when first entering
1 point 21 jigawatts!
User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

Post by origen »

Well, everything seems to be working. But, I am not able to restore Bard Songs via the "modifyBP" command. So, I did a little testing, and it seems like the script is fine, just the modifyBP command itself doesn;t do anything. If I replaced modifyBP with either "modifySP" or "modifyHP", those commands work fine.

So, it seems that in the eventAPI file, the modifyBP is not programmed correctly, and there is no way for me to even check that file.

I guess I would need the devs help on this one.
User avatar
HGamer
War Monger
Posts: 188
Joined: Thu Feb 10, 2005 7:59 pm
Location: Land of fruits & nuts, i.e. SoCal
Contact:

Post by HGamer »

Strange, I thought I had tested modifyBP and it worked. My only concern had been if a fourth parameter, like the "toZero" in modifySP, was supposed to be there (based on the contradictory text and declaration in the scripting tutorial). Apparently, modifyBP only takes 3 parameters. But the last time I touched that code (in my inn script) was in July 2004. As there were changes in the DW engine since then, it's quite possible that modifyBP got broken and nobody (until you) noticed. Just ran a quick test, and calls to modifyBP are returning 1, which I guess means success, but the Bard's BP isn't going up. :(
1 point 21 jigawatts!
User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

Post by origen »

I had run a similar test, where if it was successful, it would say a message "BP +1, Hopefully", and if it returned a failure, it would say "What the #%^$& is going on!?!"

It repeatedly gave me a success, but the BP never increased.
User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

Post by origen »

What I have noticed was that if you go into one if the normally scripted taverns, the restore BP works when you order a drink.

I am not sure if this means anything (and I was actually hoping it wouldn't work) but I ffigure it is worth mentioning.
User avatar
ShadoKnight
Nomad
Posts: 28
Joined: Mon Mar 21, 2005 2:05 pm

Post by ShadoKnight »

Sorry for the long delayed response...

The short answer to your original question is 'ultimately, you *MUST* return a value, and if you don't, the results are undefined'. The long answer has to do with functions and function chains and call stacks (it's really, really long). Basically, remember that you don't leave a function until you either return a value, or get to the end of the code, and that when you make a function call, you're jumping to the new function, which will execute to completion, then return a value, and that value will (in essence) be substituted for the function call, and execution continues where you left off. If you follow your code as originally posted, you see that you end up down a very long chain of un-completed functions, when what you really want is to return values from each state, and set up a loop of some kind (like a while() loop) to control when you're done. Sorry if that's a little too technical ;-)

As for why the restore BP works in the normal taverns, it's 'cause the in-game taverns don't use the scripting interface, they're coded in C++ in the engine. The restore BP script hook certainly *should* work, that it doesn't is likely a bug (and likely a simple bug to fix, in fact). Sorry I can't help more there ;-).

SK
User avatar
ralphtrickey
Townie
Posts: 20
Joined: Tue Apr 26, 2005 6:03 pm
Location: Colorado

Post by ralphtrickey »

ShadoKnight wrote:Sorry for the long delayed response...

As for why the restore BP works in the normal taverns, it's 'cause the in-game taverns don't use the scripting interface, they're coded in C++ in the engine. The restore BP script hook certainly *should* work, that it doesn't is likely a bug (and likely a simple bug to fix, in fact). Sorry I can't help more there ;-).

SK
The code sure looks like it should work. If someone can reproduce the problem and email me the files and directons, I can test it.

Ralph
User avatar
origen
Dark Sidhe Lord
Posts: 903
Joined: Thu Feb 10, 2005 5:54 pm
Location: Secret League of Nirulat Headquarters
Contact:

Post by origen »

I can recreate it as simple or as complicated as you want. I have to find all of my files, first.
Post Reply