Blocking function called, how so?

Started by kIM, Thu 11/10/2007 15:33:25

Previous topic - Next topic

kIM

I messed up when trying out double click code from topic 12190.0.  When I testet the game, I got the error: "Unable to open custom exe'Compiled\Testgame.exe. Global script, line 9: A blocking function was called before the first room has been loaded."

So I deleted every double click code line in the main global script, the script header, I deleted even the  hotspots. But I still get the message.

EDIT
Thank you for your suggestion, Akatosh and KrisMUC, but there is nothing in there. Game-Start is empty.
As I got error messages, I deleted the code in the game-start section and put everything  in On-mouse-click. and an' int doubleclick' on top of the global script. Now everything is deleted, also in the On-mouse-click-section. I have other code in Rep-exec, but nothing I know of with 'doubleclick'. I think I messed eround too much with the code.  ???

Maybe, as a noob at scripting with glased over eyes, I should ask for advice about my code in the forum, before trying stupid things. :-[

Akatosh

Did you check your game_start section in the global script?

Khris


kIM

Quote from: kIM on Thu 11/10/2007 15:33:25
I messed up when trying out double click code from topic 12190.0.  When I testet the game, I got the error: "Unable to open custom exe'Compiled\Testgame.exe. Global script, line 9: A blocking function was called before the first room has been loaded."

So I deleted every double click code line in the main global script, the script header, I deleted even the  hotspots. But I still get the message.

EDIT
Thank you for your suggestion, Akatosh and KrisMUC, but there is nothing in there. Game-Start is empty.
As I got error messages, I deleted the code in the game-start section and put everything  in On-mouse-click. and an' int doubleclick' on top of the global script. Now everything is deleted, also in the On-mouse-click-section. I have other code in Rep-exec, but nothing I know of with 'doubleclick'. I think I messed eround too much with the code.  ???

Maybe, as a noob at scripting with glased over eyes, I should ask for advice about my code in the forum, before trying stupid things. :-[

Did you check your game_start section in the global script?

Yes. See EDIT above. I wanted to avoid a double post, but maybe someone can still help me out?

Ashen

What was line 9 before you deleted all your code (what command, and what section, if any, of the script was it in)? And, are you still getting the error after you've removed it?
The double click code you mention (this thread) has nothing in game_start - where did the code that was there come from?
I know what you're thinking ... Don't think that.

kIM

Well, stupid at scripting as I am, I just put it above everything in global script. As I got error messages, I put the ‘int doubleclick' on top and the rest in game-start, and imported it as a function, fut rectified that after an error message.

Code:

    doubleclick = WaitMouseKey(8)*mouse.IsButtonDown(eMouseLeft);
Mouse.UseModeGraphic(eModeUsermode1);
export doubleclick;

After error messages I transferred everything to on-button-click, also the' int doubleclick'.
After some other error messages I came up with this code, and got the blocking function message. It is however possible, that, at that moment, the code was not deleted in game-start. It could be, that I forgot that and deleted it only after I got the message. I did not pay attention what was written on line 9, as I thought, the problem would be solved by deleting.

My code:
#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
int doubleclick;
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    {
  }
  else if (button == eMouseLeft) {

   ProcessClick(mouse.x,mouse.y,mouse.Mode);
    doubleclick = WaitMouseKey(8)*mouse.IsButtonDown(eMouseLeft);
Mouse.UseModeGraphic(eModeUsermode1);
export doubleclick;
}
else{
}

#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE

It is possible, that, at that moment, the code was not deleted in game-start. It could be, that I forgot that and deleted it only after I got the message. I did not pay attention what was written on line 9, as I thought, the problem would be solved by deleting.
I gess, that, with all my doings, the engine got confused and stored things somewhere I cannot get at?

I read the code in Daryls thread ‘The Dig Template”:
________________________________________
Citation about double click:
.....
*edit* new progress..

Code:
int double_click;

if (button==eMouseLeft) {
//SetMouseCursor(GetCursorMode()); // stops wait cursor appearing
double_click = WaitMouseKey(8);
mouse.IsButtonDown(eMouseLeft);
//SetDefaultCursor(2);

if (double_click) {

So I got past the error msgs.. Now I need to bind a function to the double click. Perhaps by adding a custom property to the hotspot I want to double click in? I'm not sure how to add code such as "if double_click over hotspot X, trigger player.ChangeRoom();"
Any idea?
Thanks..

-------------------------------------------------------
To add code such as "if double_click over hotspot X, trigger player.ChangeRoom();", you just create an interaction on hotspot X when it's clicked, and have something like:

Code:
import double_click; // Your global script will need a "export double_click;" on the end, too

function hotspot1_a()
{
  if (double_click)
    player.ChangeRoom();
}
-------------------------------------------------------------

Thanks a bunch man, that worked actually great, after some more research. I had to put the int double_click; up in the global script before any sectionstarts to be able to export it. I added the export double_click; like you said, and used your code in the room script but I had to add int before double_click to be able to import it. Also, even though I renamed the script-O-Name to hPortalLeft it still had to be hotspot3_a() for AGS to recognize it, a bit odd?
………………………..
______________________________________________
End of citation.

Thank you for your concern, Ashen. But if you don't see a possible solution immediately, please tell me so and do not bother. I will make a new testgame and post my code for criticism, before compiling.  Maybe you could, by the way, tell me, what is wrong in my last script in on-mouse-click. Thanks.
P.S. WaitMousekey (eight) changes into a smiley.Can't help that.


Ashen

Try this.
Top of Global Script (NOT IN ANY FUNCTIONS):
Code: ags

int double_click;
export double_click;


Global Header:
Code: ags

import int double_click;


on_mouse_click:
Code: ags

function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    int Temp = mouse.GetModeGraphic(eModeWait); // Stores default 'Wait' graphic
    mouse.ChangeModeGraphic(eModeWait, mouse.GetModeGraphic(mouse.Mode)); // stops wait cursor appearing
    double_click = WaitMouseKey(10)*mouse.IsButtonDown(eMouseLeft);
    mouse.ChangeModeGraphic(eModeWait, Temp); // Resets 'Wait' to default graphic
    ProcessClick(mouse.x, mouse.y,  mouse.Mode);
  }
  else {   // right-click, so cycle cursor
    mouse.SelectNextMode();
  }
}

(NOTE: the changing and restoring the Wait mode graphic only works if you're not using animated cursors. If you want to use them, it'll take a little more work.)

This is slightly different to the code you've been using (I think), in that on_mouse_click doesn't make any differentiation between double and single clicks. That would have to be done in the interaction scripts of whatever you click on (which it looks like the codefrom the Dig Template thread does as well). For example:
Code: ags

function hotspot0_a() {
  // script for Hotspot 0: Interact object
  if (double_click) player.ChangeRoom(3, 120, 50); // This is what happends if the player double clicks the hotspot
  else player.Walk(300, 180, eBlock); // And this is what happens with a single click.
}


For interactions where double or single click doesn't matter, just code tham as usual.

As to what was wrong with your on_mouse_click code - well, you had the export doubleclick; in there, which is wrong, and you were processing the click before setting doubleclick. Honestly, though, your post is a little chopped up to make much sense of what was going wrong. Oh, and you can avoid the 8) smiley by either putting a space between the 8 and the ), or by using the code tags ([ code] and [ /code], without the spaces). I'd also recommend you use the quote tags, to make it clearer what's - well - a quote, and what's your comments.
I know what you're thinking ... Don't think that.

kIM

Sorry, no buttons appear in my window, only smileys. I will try to be clear.

After my last scripting catastrophe I made a new testgame. Now again, after I did something wron again, I got the message: Unable to open custom exe 'Compiled\Poging1.exe' for writing.

What I did:

1)
In Room1 I created a hotspot( hotspot2) with a property ‘exit' to differentiate it from other hotspots in rep_exec  in the global script, where I define my cursor graphics.
In the interaction editor I run a script that works fine:
Code:
// script for Hotspot 2 (Hotspot 2): Look at hotspot
if(mouse.IsButtonDown(eMouseRight)){
  player.ChangeRoom(2, 240, 140);
}
if(mouse.IsButtonDown(eMouseLeft)){
   character[CHARACTER].Walk(187, 119,eBlock);
   DisplayMessage(4);
}

2)
Also in Room 1 I created a second hotspot (hotspot3) with the same ‘exit' property and the same code. Only the numbers were differernt. So, message(4) became message(3). It works fine.

3)
In Room3 I created a similar hotspot with similar code and with the same DisplayMessage(3).
I got an error:In room3 script(line13) DisplayMessage:Invalid message number to display.
:-[Of course, it referred to a room message of another room! :-[

4)
Here it comes:
I created a global message 500 with the same words and adapted the message numbers for the hotspots in both room scripts.
After that, everything was grey in the file menu, exept prefernces, I think.  I even could not quit the program. In fact, I could not do anything anymore. A crash?

5)
I forced quit with Ctrl+Alt+Delete.
After that I get the ‘Unable to open …' message, when CHARACTER has walked to the coordinates in Room3.

Does someone know a remedy for this illness?

By the way, Ashen, I did not use the double_click code because it seemed to interfere with my cursorgraphics. When I deleted the lines referring to the Wait graphic, it did not work at all. Anyway, thank you for your answer and the trouble.

I would also like to know what the character ‘*' means in the following code:
double_click = WaitMouseKey(10)*mouse.IsButtonDown(eMouseLeft);
I  only understand for example this:
Hotspot*myhotspot;
myhotspot= whatever_that returns a value;
The pointers for newbies section did not make me wiser

Thanks to anybody who can help me.


Ashen

Quote
Sorry, no buttons appear in my window, only smileys
Who said anything about buttons?

Quote
I got the message: Unable to open custom exe 'Compiled\Poging1.exe' for writing.
Quote
After that, everything was grey in the file menu, exept prefernces, I think.  I even could not quit the program. In fact, I could not do anything anymore. A crash?

Did you have the game running at the time? If the game is running - or if an error popup (like 'Invalid message', 'Abort key was pressed', etc) hasn't been closed - then the 'File' menu should be greyed out. The Editor title bar will also say [Running](Game name) - Adventure Game Studio Editor. Close the game (not the editor) or any popups, and that should clear itself. Similarly, the 'Unable to open exe' error only occurs for me if I try to test a game that's already running (either started by running the exe directly, or in another instance of the Editor). Close any running versions and that should clear up. If you didn't know you HAD any other instances running, use Ctrl-Alt-Delete and check the Task Manager for one that hasn't properly shut down. (Which would be another problem entirely, and one I couldn't help with  :-\)

Quote
I would also like to know what the character ‘*' means in the following code:
...
The pointers for newbies section did not make me wiser
It wouldn't, becasue that's nothing to do with pointers. In this case, * is being used in a mathematical sense. The line means 'doubleclick' equals 'WaitMouseKey(10)' multiplied by 'Mouse.IsButtonDown(eMouseLeft)'.

WaitMouseKey returns a value of 1 if it's interupted (i.e. if you click again while it's waiting - a double click) or 0 if it's allowed to run (i.e. a single click). IsButtonDown(eMouseLeft) returns 1 if the left mouse if down, 0 otherwise. So, doubleclick can only be 1 (and trigger any code that needs a double click) if the wait was interupted by a second left mouse click. If there's no second click, or if it's a right click, doubleclick equals 0 and the code is run as normal for a single mouse click. Hope that makes sense...
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk