Problems with unhandled_event() in 2.6

Started by BuRRe, Fri 26/12/2003 00:03:44

Previous topic - Next topic

BuRRe

I have just changed my game from 2.56d to 2.6, and I noticed two rather disturbing things:

I had a
function getPhase(void)
that I had to change to
function getPhase()
to get it to work properly, not to hard but since I'm also a hobby-C-coder it would be nice if void would work properly  :)

my unhandled_event() is without any inparameters, and it worked fine with 2.56d. now whenever an unhandled_event() is called the game crashes with the following problem:
"Error: run_text_script1:error -1 (Runtime error: wrong number of parameters to exported function 'unhandled_event') running function 'unhandled_event'"
Why has this been changed, and do I have to remake my unhandled_event and all calls to it? I probably will, because I see it's like that in the help, but I just wanted to post this because it (for me) was a major change between the versions.

Just my two cents, not to be taken to seriously  :D

evilspacefart

Just try this in your global script:

function unhandled_event (int what, int type)
{DisplaySpeech(EGO,"Huh?");}

one reply for every unhandled event    ::)

BuRRe

Sorry, I don't think you understand my problem..
the problem is that I have coded with a "blank" unhandled_event (without any inparameters), and I have called it several times, without any paramteters, and it worked fine until I got 2.6 up'n'running..
for some reason you can't have a "blank" unhandled_event() in 2.6, but you could in 2.56d.. so I just wanted to make ppl aware of this. I know, it's my fault entirely, since I didn't use the standard at first hehe.. and I have changed it now.. but as I said, just to make ppl aware of this change, since it wasn't listed (as far as I could see at least, and it IS a change)

Just my two cents, not to be taken to seriously  :D

Proskrito

yep, in early versions AGS didnt check if those functions had the correct number of parameters, but in order to not get some strange problems, now it does.
Just put the two parameters and never use them in the function, like : unhandled_event(int xxx, int yyy ) and never use xxx and yyy variables.

for the first one, i think AGS cant be made to look like every other programming laguage that each AGS user is used to, so i think the best way is that you get used to it  :)

Paper Carnival

what's the benefit of not using parameters?

Proskrito

Quotewhat's the benefit of not using parameters?
Flexibility. some people could not like the default 'type -what' thing, and they can script their own way to handle unhandled event messages, so the default parameters arent used. Its not exactly an 'advantage', just that parameters can be superfluous sometimes.

BuRRe

On the other hand, you could easily add more "values" than what's originaly set, and in that way enhanche the use of it.. but still, I think you should be able to set whatever number of input parameters that you want.. although I understand if it's not really a top-priority fix hehe

Pumaman

These problems are due to the script compiler in 2.6 being stricter about mistakes in the script.

QuoteI had a
function getPhase(void)
that I had to change to
function getPhase()
to get it to work properly, not to hard but since I'm also a hobby-C-coder it would be nice if void would work properly

"void" is not a supported type by the scripting language, thus this probably never worked properly. I appreciate that it was that way in C, but even in C putting 'void' in the parameter list has been obsolete for 10 years now ;)

Quotemy unhandled_event() is without any inparameters, and it worked fine with 2.56d. now whenever an unhandled_event() is called the game crashes with the following problem:

Again, your parameter-less version should never have been accepted by the compiler. The reason is that the AGS engine calls into your unhandled_event function with two parameters. If you have more or less it will corrupt the stack and could well lead to strange results.

Shadow

Quote from: evilspacefart on Fri 26/12/2003 01:08:13
Just try this in your global script:

function unhandled_event (int what, int type)
{DisplaySpeech(EGO,"Huh?");}

one reply for every unhandled event    ::)

I have the same Problem, but I don'T understand anything (a little bit maybe) of this. What do I have to enter as int what and int type????? Can someone give an example???

Pumaman

Well, that is the way unhandled_event works. Without those parameters, you can't tell what the player tried to do so you can only give one generic "I can't do that" message.

You need to declare it as follows:

function unhandled_event(int what, int type) {
Display("You can't do that");
}

but the point is that you can use the what and type parameters to find out what they tried to do, and thus give a different message if they tried to talk to something rather than look at something.

Look up "unhandled_event" in the manual for a full list of what the possible values mean.

evilspacefart

a parameter is like so:

if ((what==1) && (type==4)) //Talk to a hotspot unhandled
{DisplaySpeech (EGO, "Gee, I think it's ignoring me.");
}

So you walk up and try to talk to a fire hydrant hotspot that doesn't have a "talk" interaction, it will say "Gee, I think it's ignoring me."

Like the Pumaman said, you can read the help file on unhandled_event.

*sorry but I think people who talk to fire hydrants is funny*

Shadow

 ;D Okay I think I understud that so far :D I will read the section in the help. thank you!

Shadow

Okay, I added this to the Global Script:
----------------------------------------------------
/**/function unhandled_event(int what, int type){
/**/if ((what == 4)&&(type == 2)){
/**/DisplaySpeech (EGO, "What???");
 }
}
//////
-----------------------------------------------------------------
After this, I had to put in the numbers for the unhandeled event here (its the script from the Scumm template, yes):
-----------------------------------------------------------------
function inventory1_a() {
 // script for inventory1: Other click on inventory item
if (UsedMode("open")) Display("Abriendo");  
else unhandled_event(5, 4);  // 5, 4 are int what and int type for other click on inventory
}

function inventory1_b() {
 // script for inventory1: Look at inventory item
Display("mirando");  
}

function inventory2_a() {
 // script for inventory2: Other click on inventory item
if (UsedMode("push")) Display("empujando");  
else unhandled_event(5, 4);
}


function inventory3_a() {
 // script for inventory3: Other click on inventory item
 
if (UsedMode("push")) Display("empujando");  
else unhandled_event(5, 4);
}
-----------------------------------------------------------------------------------
Now it works, I can move around, but when i want to use something it just do nothing. There is no effect on anything I do. I can't pick up objects, or even use them.
I think it has something to do with the things I edited in the Global Script. But what??????????????????????????????????????????




Proskrito

#13
if you are using the scumm template, yo can do 2 things:
1- Use the new templates that have this problem fixed. yo cand find them here: http://www.agsforums.com/yabb/index.php?board=2;action=display;threadid=6642;start=msg122548#msg122548

2- leave the unhandled_even as it was, but instead of defining the unh.ev. fuction without parameters, put 2 ints, although you wont use them, like
Code: ags
function unhandled_event(int blah, int bleh){ ... 
instead of just
Code: ags
function unhandled_event(){ ... 
and modify the script header to add the two parameters in the 'import unhandl...' line.

Hollister Man

Shadow:

You don't need to call unhandled_event, the game does that itself whenever an event occurs that you don't tell the game what to do (IE it is unhandled.)  If you click on a hotspot (or a blank area on the hotspot map) that has no interaction, it will call unhandled_event.  Check out the demo game's unh_ev script, it might help you some, and read the manual
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

SMF spam blocked by CleanTalk