Scripting animating cursors

Started by kIM, Mon 24/09/2007 16:50:15

Previous topic - Next topic

kIM

Hallo, his is my first post.

I have no experience with scripting and please excuse my lack of experience with wrighting english too.

I made a script about cursors(see far below), but cannot test or save my game because of following error message: There was an error compiling your script. The problem was: In ‘Global script ‘
Error (line 36): Nested functions not supported (you may have forgotten a closing brace).

I am not aware, that I changed anything in this default script, and I do not see something wrong:

#sectionstart on_key_press  // DO NOT EDIT OR REMOVE THIS LINE
Line 36:  function on_key_press(int keycode) // called when a key is pressed. keycode holds the key's ASCII code
  {
  if (IsGamePaused()==1) keycode=0; // game paused, so don't react to keypresses
  if (keycode==17) QuitGame(1); // Ctrl-Q
  if (keycode==363) SaveGameDialog(); // F5
  if (keycode==365) RestoreGameDialog(); // F7
  if (keycode==367) RestartGame(); // F9
  if (keycode==434) SaveScreenShot("scrnshot.pcx");  // F12
  if (keycode==9) InventoryScreen(); // Tab, show inventory
  if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
  if (keycode==22) Debug(1,0); // Ctrl-V, version
  if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
  if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
  }
#sectionend on_key_press  // DO NOT EDIT OR REMOVE THIS LINE

Maybe I can delete the whole thing, as I do not use it?

The script I wanted to test should change the mouse.Mode automatically to eModeInteract, wenn over a hotspot, etc. and animate with view INTER, loop 0. When I only change the curor mode automatically, the animation does not work any more. So I must tell the engine in a script, to animate.
I wrote one inspired from a respons from Ashen to a question about animating a cursor wenn over one specific hotspot. Mine is meant to work in all the rooms and also on regions. On regions I want to change the cursor graphic to still another one, also animating, but for a beginning I prefer to try this script first., because I do not know yet where to put the region thing with the Region.GetAtRoomXY …. function in the script. I am sorry, it all looks very complicated to me.

Code:

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE{
  // put anything you want to happen every game cycle here

int cursorset;
function repeatedly_execute(){
if(GetLocationType(mouse.x, mouse.y)==eLocationNothing)
  if(cursorset==0){
mouse.Mode=eModeWalkto;
cursorset=1;
}
else{
  if(cursorset==1){
    mouse.Mode=eModeInteract;
    Mouse.ChangeModeView(eModeInteract,INTER);
   
cursorset=0;
}
}


Maybe I should use global integers here, but I have no clue how to do that.

If anyone with experience would tell me if there is something wrong with what I have written and explain it to me, I would be gratefull.

Kim


Khris

Wow, you've seriously messed up the braces.
First of all: indent your code properly!

The reason for the error you're getting is at least one missing "}" before on_key_press.

The layout of repeatedly_execute should look like this:
GLOBAL VARIABLE DECLARATIONS HERE

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here

  LOCAL VARIABLE DECLARATIONS HERE

  YOUR CODE HERE

}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

kIM

I did not expect an answer so soon. Thank you KrisMUC. I quit the game without saving. Later I testet it and there was no error message about the on_ key_press function any more. After some “cleaning up” I testet again, and every thing worked. But I am not happy with it because of the slowness. I have sometimes to hover again and again over hotspots and objects, going from one to another, before the cursor changes into the animating one. I also had a region covering a small colum on the richt side of the window, with no interaction at all, and wenn I clicked on it in Walk mode, EGO displayed a message that was meant for a hotspot somewhere in the middle of the window? ?? There are definitly things I do not understand. This game has resolution 640-400, and 8  bit colors.

Kim

Khris

Try this:

Code: ags
function game_start() {

  mouse.ChangeModeView(eModeInteract, INTER);

}

function repeatedly_execute() {

  if (GetLocationType(mouse.x, mouse.y)!=eLocationNothing) mouse.Mode=eModeInteract;
  else mouse.Mode=eModeWalkto;

}


I'm not sure why you are using that cursorset variable, but it's probably the reason for the behavior you get. It seems to delay the change.
About the region: check its interactions.
I hope you didn't manually rename any of the room script functions AGS created (like hotspot1_a and the like).

kIM

#4
I tried it, but without the variable, the cursor does not animate at all.
Thanks anyway.

EDIT:
I tried this code and it works perfectly:

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE{
  // put anything you want to happen every game cycle here
function repeatedly_execute(){

if(GetLocationType(mouse.x, mouse.y)!=eLocationNothing)
if(mouse.Mode==eModeWalkto){
  mouse.SaveCursorUntilItLeaves();
  mouse.Mode=eModeInteract;
}
else{   
}
}
  :D I am happy as a kid.

Ashen

Please don't double post.

Also, couldn't you trim that code down a little, to this:
Code: ags

function repeatedly_execute(){ 
  if(GetLocationType(mouse.x, mouse.y)!=eLocationNothing && mouse.Mode==eModeWalkto){
    mouse.SaveCursorUntilItLeaves();
    mouse.Mode=eModeInteract;
  }
}


The two if lines can be merged into a single condition (since you don't have a { after the first, they're run that way anyway), and because you don't have anything happening in the else condition, you shouldn't need to have it.
I know what you're thinking ... Don't think that.

Khris

So it looks like changing the mode to an animated one constantly will keep the animation from playing. Sounds like a bug.

SMF spam blocked by CleanTalk