having trouble with on_event

Started by Rui 'Trovatore' Pires, Wed 21/05/2003 19:34:47

Previous topic - Next topic

Rui 'Trovatore' Pires

It's very odd. I've got 3 on_event events - ADD_INVENTORY (when it checks to see whether the user has more than 9 items in the inventory, and if so activate the scroll up/down buttons), LOSE_INVENTORY (which performs the same check AND clears the image in the toolbar in the LAST INVENTORY USED button) and GIVE_SCORE (where a ranking is given, randomly).

So far, so good.

Now, the problem - it seems each of these is only triggered if one of the others hasn't already. To wit - if I get a point BEFORE getting or losing an item, the GIVE_SCORE thing will run but it's almost a certain thing that ADD_INVENTORY and LOSE_INVENTORY won't. Likewise, doing ADD_ or LOSE_ will negate the other and GIVE_SCORE.

Am I using this wrongly? Is it a feature I'm mis-using? Is it a bug? Have I screwed up royally somewhere? Would you help me? Do you want to see my code? Should I shut the bloody hell up?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

BlackBaron

I had to do something similar and I didn't use the on_event function at all, I just add a bit of code into the repeatedly_execute function that does the appropiate checks and then enables or disables the scroll arrows.

Hope that helps you.
Ask if you want me to be more specific.
"Do you thirst for knowledge no matter the cost?"
            -Watrik, master glassblower

Rui 'Trovatore' Pires

It might have helped, if it weren't for two other things -

1-I'm avoiding using the global repeatedly_execute, it makes the debugging menu completely useless.

2-It shouldn't work this way. Despite what I said about my own possible mistakes, I think it's a bug.

But hey, if I don't get any better solutions, you can be sure I'll consider your suggestion. Thanks!
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

It may well be a bug - how are you adding the score and inventory when this problem arises? I mean, are you using the interaction editor or do you have a script running GiveScore and AddInventory?

Rui 'Trovatore' Pires

Using GiveScore and AddInventory, and LoseInventory. I only work in the scrip editor if I can, I prefer it.

Oh, and since CJ is here - (this is offtopic, I know, but I can't resist) why are there conditionals in the Interaction Editor but no Else? I work around it with the Stop Running More Commands thing, but really... :)
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Rui 'Trovatore' Pires

I tested further, and lemme tell you, this is really weird. It's not at all what I thought at first - actually, it seems that it whenever the on_event thing is called from a REPEATEDLY_EXECUTE that it doesn't work.

However, it's not so in ALL places. I have at least one place where I call both LoseInventory and GiveScore from repeatedly_execute, and both work fine. I also tried doing this action before and/or after the ones who don't work, and nothing changed - that one still worked, the others still didn't.

This is weird!
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

Which version of AGS are you using, out of interest?

I just tried putting this in repeatedlyt_execute:

GiveScore(5);
AddInventory(1);
GiveScore(10);

just to be sure, and on_event was run three times.

Quote
Oh, and since CJ is here - (this is offtopic, I know, but I can't resist) why are there conditionals in the Interaction Editor but no Else? I work around it with the Stop Running More Commands thing, but really...

I think it was about that time that I got bored of coding the interaction editor  :P

Rui 'Trovatore' Pires

The latest one. And, if you're having trouble replicating the problem, you can go to the critic's lounge and download my Larry 2 Teaser. Here's how to replicate the problems in my game -

1-look at garage, use garage - note that score AND ranking changed
2-go north, north, north, then all the way east. Go inside Quiki-mart
3-use machine on counter. Type in any 6 numbers. Note that score AND ranking changed, this one ON repeatedly_execute
4-leave, go all the way east, enter KROD, show the ticket to the girl, type in the numbers she says. NOTE that score changes but ranking does NOT, as it should per on_event. Also, note that the toolbar button next to the inventory is grayed out, but only because I grayed it out when I found out on_event wouldn't (my on_event LoseInventory states that the button will be grayed out whenever the player loses an item).
Out of curiosity, sit down and wait for the guy to come in, then stand up and follow. Watch the dating show, and note that when the score changes, the RANKING does NOT - and it was called on repeatedly_execute. If you check out the lottery show, you'll experience the very same problems. BUT between both shows, when Larry gets the cruise ticket, BOTH score and ranking will change! This one (the cruise ticket) is NOT, by the way, repeatedly execute.

I've been over my code again and again. You can see it if you want to, but I doubt the problem's there.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

Is there a pattern at all in that it doesn't work when it happens as part of a long cutscene, but it does work if the player just performs one action to do it? Does that sound right at all?

I'll take a look at the game once it finishes downloading, but it's freewebs and it's taking a while.

Rui 'Trovatore' Pires

Funny you should mention that. It HAS crossed my mind, and it seems right, but there's no reason for it to be so, especially when you consider that once he enters the dating game interactivity only returns when he steps back into the waiting room, after he's given his prize - but when he IS given the prize, the ranking does change! Makes little sense.

I thought, "Hey, maybe it needs some time to kick in, like sometimes graphic stuff needs Wait(1) before a display or else it will only be refreshed after the text goes out", and so added Wait(1) in the appropriate places BEFORE he goes in the waiting room, AFTER he's given the girl her numbers. Didn't work.

I'm more advanced in the game now, and I can definetely say that AddInventory isn't working right. I Ctrl-S to get everything, and then get one extra item, which should tell on_event that I've got more than 9 items, and so it should display the scroll arrows. Nothing happens late in the game, but it works early on. Try this - Ctrl-S, then go to the drugstore and put the suscreen where it belongs (left side of the room, blue bottles), then pick it up and check inv. Try it again much later on, say after the lottery.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

This is strange, and is probably related to AGS only allowing one script to be running at a time.

As a workaround, what you can do is create your own GiveScore function, something like this:

function AddScore (int amount) {
 GiveScore (amount);
 // update rank
 SetLabelText (blah blah blah);
}

then just use AddScore in your scripts instead of GiveScore.

That way, you don't need to use on_event for GotScore. I'll look into it in the meantime.

SMF spam blocked by CleanTalk