I see no sensible reason as to why this doesn't work:
Script header:
short SharpBlade; //Whether the sharpener is a blade or normal.
Other Click on inv 10 (sharpener)
if (GetCursorMode()==8) {//if open
if (SharpBlade==0) {//if blade is not removed
Display ("Mark opens the sharpener and removes the blade.");
SetInvItemPic(10,92);SetInvItemName(10,"Blade");//Switch to blade
SharpBlade=1;return;}
else if (SharpBlade==1) {//if blade is removed
Speak ("That doesn't open.");}}//unhandled event
else if (GetCursorMode()==5) {//else if pick up
Speak ("I already have it.");}//unhandled event
Interact with hotspot 1 (floss dispenser)
if (player.activeinv==10) {// If sharpener/blade
if (SharpBlade==1) {//If blade is out sharpener
Walk (123,103);
AnimateCharacter(MAR,13,15,0);Wait(15);
Display ("Mark places the blade in the dispenser.");
bladein=1;LoseInventory(10);}//Set it so the blade is in
else if(SharpBlade==0){//if blade is still in sharpener
unhandled_inv();}}//unhandled event
else {
unhandled_inv();}//unhandled event
Well that's basically it. All it gives me is unhandled_inv everytime I use inv 10 on the hotspot.
Please help. I really see absolutely no reason for this not to be working.
Thanks, z0r.
The first question seems fairly straightforward. If your problem is that you pass the screen coordinates as room coordinates, the solution is to NOT DO THAT.
Instead, convert them like this:
FaceLocation(EGO, mouse.x + GetViewPortX(), mouse.y + GetViewPortY() );
I think he means that the engine automaticly passes the co-ord as that
no it works fine now ... How did I not think of that? I think it's 'cos I'm dumb...
now on to #2 folks...
Try removing the last Wait(1) next to FadeIn(1), and see if it helps.
If it doesn't help then what if you remove the othe Wait(1) as well?
It's definately not the wait commands, because FadeIn and FadeOut are blocking commands, acting like Wait.
I've just tried something similar and it doesn't flicker for me. What's the code behind the FaceLeft() function?
Well yeah just remembered that now.
function FaceLeft () {
FaceLocation (MAR, player.x-10, player.y);
Wait (1);}
I tried without the wait and it just fades in to black and thern everything pops up, like instantly. I know this because I can only see my cursor fade...
Perhaps try setting the "Room transistion style" option to something different (such as Dissolve) and see if you still get the "flicker"?
You could also run the command from a script (Before Fadein for example), somthing like:
SetScreenTransition (TRANSITION_DISSOLVE);
You might also try using the "Resources split every MB" option (1 or 2 or 3 MB), and see if adjusting those settings will improve things for you?
I dunno, just some thoughts that might help.
Hmmm I think ScreenTransition types won't affect background frame changing.
What colour depth was your game in?
If it's 256 colour, try to make the frames share the same palette when importing, if they use independent palettes I think that flash is hard to avoid.
[EDIT]
Ah, yeah Gil is right.
FadeIn wouldn't work correctly unless a Wait() command was called. Wait(1) updates the screen (to reflect the changes being made by SetBackgroundFrame(0))but, here unfortunately, the palette is updated as well, so we see a new frame for a moment.
Sharing palette should do the trick but if you can't share the palette for some reason then the only way out is to write our own fadein/fadeout functions.
Take a look at the following thread: http://www.agsforums.com/yabb/index.php?topic=8484.msg103906#msg103906 in the Technical Archive forum.
There is a code I have written before. Using it we can have:
at the top of room script:
import function SavePalette();
on fading in/out:
SavePalette();
fadeout(0,0,0,63);
ReleaseCharacterView(MAR);
ReleaseCharacterView(BOS);
GUIOn(0);
FaceLeft();
SetLabelColor (0,13,40);
SetLabelText(0,13,"Walk to");
SetBackgroundFrame(0);
SavePalette();
fadein(0,0,0,1);
How does it turn out?
Well, I guess that did the trick. There wasn't really need to post all that script, all I needed to do was to share the pallette.
Thanks guys!
Hehe, I just decided to give it a go and carry out a research on what can we do if backgrounds having different palettes is an issue, since anyway the fadein/out function had been written before. Then I shared the results. :)
updated first post.
Hmm, what if you replace "if (player.activeinv==10)" with "if (character[GetPlayerCharacter()].activeinv==10)"?
It doesn't make any difference.
Did you try that and it doesn't work? Hmm, try adding Display()s before each 'if' statement to display the condition value, like:
Display("player.activeinv=%d", player.activeinv);
if (player.activeinv==10) {// If sharpener/blade
Ã, Ã, Display("SharpBlade=%d", SharpBlade);
Ã, Ã, if (SharpBlade==1) {//If blade is out sharpener
Ã, Ã, Ã, Walk (123,103);
Ã, Ã, Ã, AnimateCharacter(MAR,13,15,0);Wait(15);
Ã, Ã, Ã, Display ("Mark places the blade in the dispenser.");
Ã, Ã, Ã, bladein=1;LoseInventory(10);}//Set it so the blade is in
Ã, Ã, else if(SharpBlade==0){//if blade is still in sharpener
Ã, Ã, Ã, unhandled_inv();}}//unhandled event
else {
Ã, unhandled_inv();}//unhandled event
Three suggestions (don't know if any will help, but best to check):
1.
(What Scorpiorus said, while I was typing.)
2.
Try using the item name, rather than SharpBlade, e.g.:
if (player.activeinv==10) {// If sharpener/blade
Ã, string name;
Ã, GetInvName (10, name);
Ã, if (StrComp ("Blade", name) == 0) {//If item is called Blade
Ã, Ã, Walk (123,103);
Ã, Ã, AnimateCharacter(MAR,13,15,0);
Ã, Ã, Wait(15);
Ã, Ã, Display ("Mark places the blade in the dispenser.");
Ã, Ã, bladein=1;
Ã, Ã, LoseInventory(10);
Ã, }//Set it so the blade is in
Ã, else unhandled_inv();
}
else unhandled_inv();
(not sure about the scripting)
3. (least likely)
QuoteInteract with hotspot 1 (floss dispenser)
(from your first post).
Check the code is in the 'Use inventory on hotspot' interaction, and not 'Interact hotspot'.
Scorpiorus: I did those debugging displays like you said, and when I pick up the sharpener SharpBlade is 0. That's fine.
When I open it SharpBlade is 1. That's fine.
When I look at it and it's open, it's 1. That's fine.
When I look at it and it's closed, it's 0. That's fine.
When I use it on Hotspot 1, it's 0. How does it go from 1 to 0? What sets it like that?
Ashen: Amazingly, this works. I's still like to find the origin of why it didn't work before though.
Maybe because declaring variables in the script header actually creates seperate variables for the global script (inv interaction) and each room (hotspot interaction)?
Probably, define a variable in the header only if you want to have variables of the same name that can be set independently in different rooms.
If you want the variable to share value between rooms, you need to declare it in the global script (not header), export it and then import it in the header for each room.
For example:
Global script:
int blah;
export blah;
Script header
import int blah;
Perhaps. But I tried with global ints as well and that didn't work.
Sorry Gilbert! I only saw your post now! Yes I was using that before you posted and it worked fine, I just wanted to know if the fact that the script header made independent variables was a mistake, or intended.
Well, thanks and cheers.
It's intended, because what the header actually do is that the content of the header is inserted to the top of each of the room scripts.