Re: Ionias' scripting woes. (SOLVED!)

Started by Ionias, Thu 29/03/2007 05:11:56

Previous topic - Next topic

Ionias

Ok, I must be doing something wrong. I need to pull the hotspot property from the global script. Is this even possible?

What I'm trying to accomplish is this. Let's say Room1.crm has a hotspot called hExit. That hotspot has the property called Sprite. That Sprite property stores the variable of the sprite image I want the mouse to turn into when it's over top of the hotspot.

Here is what I have so far:

Code: ags

				if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot) { // mouse over an EXIT hotspot?
						if (Game.GetLocationName(mouse.x, mouse.y) == "eNorth") { // mouse is over the north EXIT hotspot
								Mouse.Mode = eModeEXIT;
								TRUE_mouse_mode = 4; // exit
								Mouse.ChangeModeGraphic(eModeEXIT, GetGlobalInt(1)); // north sprite


Now I want to change that GetGlobalInt(1) to the hotspot property sprite, but I have no idea how. Anytime I try to put hExit in it's place I get compiling errors. Any help with what I'm doing wrong? :/

Candle

I'm not sure what your trying to do but maybe this would help?
MODULE: OtherRoom
Yet another plugin conversion: Here's my OtherRoom script module for AGS v2.7, inspired by the OtherRoom plugin by Steve McCrea.

This script module simplifies the process of enabling/disabling various things in rooms other than the one the player is currently in. This is especially handy for beginners.

Features:

* Turn on, off and toggle hotspots and regions in other rooms
* Turn on and off walkable areas in other rooms
* Turn on, off, fade, toggle and position objects in other rooms
* Get current status of things in other rooms

Advantages to the OtherRoom plugin:

+ Cross-platform compatibility
+ Additional commands (object fading, get current status)
+ Extensible & customizable
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=20650.0

Khris

#2
Since hotspots (and objects, too) are room-dependent and only the current room is present in the RAM at any one time, you cannot reference them by their Script-o-name in the global script.

Simply use the hotspot[] array or a pointer:

Code: ags
  if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot) { // mouse over an EXIT hotspot?
    Hotspot*h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
    if (h.GetProperty("Exit")) {
      mouse.Mode = eModeEXIT;
      TRUE_mouse_mode = 4; // exit
      mouse.ChangeModeGraphic(eModeEXIT, h.GetProperty("Sprite")); // north sprite


As you can see, I've used a boolean property called "Exit" to distinguish the exit hotspots from normal hotspots.
And keep in mind that the actual mouse is referenced by "mouse", not "Mouse" (the latter being the class, the former being the actual instance representing the mouse pointer).

Edit: Actually one property is enough. Just use an int, 0=no exit, 1=north, 2=east, and so on.
This code probably is in you rep_ex, so put this above:
Code: ags
int exitsprite[5];

Inside rep_ex:
Code: ags
  exitsprite[1]=NORTHSPRITE; // sprite number
  exitsprite[2]=EASTSPRITE;
  ...
  ...
      mouse.ChangeModeGraphic(eModeEXIT, exitsprite[h.GetProperty("Exit")]);


Ionias

#3
Quote from: KhrisMUC on Thu 29/03/2007 06:40:31
Code: ags

Hotspot*h=Hotspot.GetAtScreenXY(mouse.x, mouse.y);

Awesome! That was my problem in a nutshell. I was trying to put that line of code within the hotspot reference instead of assigning it. Thanks again.

Candle: Thanks for the module add-in link. I've downloaded and I'll take a look at it.

*Edit*

Just tested it and it works like a charm! Now I can have custom exit the room sprites based on the exit hotspot in question. (ie. If the hNorth hotspot wasn't true north.)

*Edit 2*

Ok, having another problem with my Exit hotspot routines. :(

Code: ags

if (player.Name == "Cyborg-inator") { // cyborg is the player character
  if (player.Moving == true) { // cyborg is moving
    if (IsTimerExpired(3) == true) { // shake screen
      ShakeScreenBackground(10,1,20); // tiny shake 1 second
      SetTimer(3, 51); // reset the timer
      }
    }
  else { // keep the timer reset so no screen shakes durning non-movement
    SetTimer(3, 41); 
    } 
  }


The above code works perfect for the normal click and walk. However, when I click on the exit hotspot and call an eBlock walk, the timer stops updating and the screen stops shaking?

Does eBlock stop the timer?

Candle

I think eBlock wi;ll stop everything till the eBlock is release.

Khris

Unless the game allows to switch the player character, you don't need the first if.

I assume the screen is supposed to shake whenever one of the feet hits the ground?
Since there aren't any blocking commands in that piece of code, try putting it in repeatedly_execute_always (you might have to create it yourself if it doesn't exist already).

Another solution:
Code: ags
int oldframe;

function repeatedly_execute_always() {
  if (player.Moving && player.Frame != oldframe) { // make sure we've reached the next frame
    oldframe=player.Frame;
    if (oldframe==3 || oldframe==6)  // replace with "left/right foot hits ground" frames 
      ShakeScreenBackground(10, 1, 20);
  }
}

Ionias

Yes, you can switch characters in this game. I don't see a spot to add the repeatedly_execute_always section. Do I just edit it into the global script myself with:

Code: ags

#sectionstart repeatedly_execute_always  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute_always() {

  // code goes here

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


I assume?

Either way, that above code sample you've given me will work better in the long run. I'll just need to go back through and find the frame(s) I'm looking for. Thanks a million!

Ashen

You don't need the sectionstart/end lines for your own functions, but otherwise that's right. (They won't do any harm if you have them, but they don't do any good either.)
I know what you're thinking ... Don't think that.

Ionias

So I'm confused, is repeatedly_execute_always() a built in AGS function that will always repeat? ... or is this a custom function that I would have to make sure gets call from with AGS's rep_exe section?

Kweepa

It will automatically be called if it is defined in the global script, so in that sense it's a built-in AGS function.
It's different from code in the repeatedly_execute section as it's called even when blocking functions are in progress. So you can't call a blocking function from it.
Still waiting for Purity of the Surf II

Ionias

Thanks very much for the info. Was wondering if anyone can help with another problem.

No matter what I try I can't get the AGS text window to display an alpha blended sprite. With my other GUI's the buttons never display the alpha blending, but the background image at least does.

Is there any kind of work around to have an alpha blended re-sizeable text box? The best I can come up with is a GUI with an alpha blending graphic and a label. However, that would hardly be able to be resized based on the text output. :/

Ionias

#11
I've run into another problem.

I'm using 4 mouse modes. eModeFatman, eModeSuper, eModeAqua, eModeCyborg, for each of my 4 player characters. These modes are #10-#13. In the editor's general settings I have Walk to hotspot in look mode unchecked. I have the Don't automatically move character in Walk Mode. checked.

If I'm correct the player character should NOT move if he's looking at something or walk to it unless I manually script him to move to that hotspot. However, here is what happens…

When I give a hotspot a walk to point in the room editor the character will move to the hotspot every time I click on it. When I remove this walk to point from the hotspot in the room editor it behaves like I want it to. The player will not walk to the hotspot unless I script him to the manual x, y coordinates.

Is this how it's supposed to work? Does giving a hotspot a walk to point over ride all the general settings?

It would be a real pain to script each x, y coordinates for every hotspot visual walk to point provided in the room editor. What am I doing wrong?

*edit*

Further testing reveals that the player characters will auto-walk to any other characters in the room on any action. So removing the walk to points only solved the hotspot problem, there is still an underlying problem somewhere that is causing AGS to handle the walk to events instead of allowing me to control it via script. Grrr.


Khris

I've tested it and my character moves to the walk-to point everytime, except when I use the look mode, so it works like intended, at least on AGS's side.

Neither of the settings apply in your case, since you are neither using the look nor the walk mode.
As a workaround, don't switch to the extra cursors but keep the mode set to look and change the mouse pointers graphic only.
Code: ags
  mouse.ChangeModeGraphic(eModeLook, FATMAN_CURSOR_SPRITE);


Then put something like this in on_mouse_click instead of ProcessClick():
Code: ags
  // set Hotspot h to the Hotspot under the mouse cursor like in rep_ex
  if (mouse.Mode==eModeLook) {
    int mg=mouse.GetModeGraphic(mouse.Mode));
    if (mg==FATMAN_CURSOR_SPRITE) h.RunInteraction(eModeFatman);
    if (mg==AQUA_CURSOR_SPRITE) h.RunInteraction(eModeAqua);
    ...
  }
  else
    ProcessClick(mouse.x, mouse.y, mouse.Mode);

Ionias

Drat, that's what I was afraid of. Thank you very much KhrisMUC, again! That last batch of code will save me from a massive rewrite. :)

Ionias

Ok, I have four playable characters all sharing the same GUI called gTxtbox. I change the border graphics colors to match the current player character. For example if the current player character is Fatman then the GUI appears as yellow border. The inside of the GUI is white with black text. Here is my problem...

I want to display the dialog options on this GUI. However, when I do that the options show up as color 15 (white) and are hidden from view because of the white background of the GUI. Changing the background color of the GUI to anything other than white doesn't have that same comic-book feel.

After doing some searches I found that the GUI.changefontcolor command is on the tracker, so it will be added at some point. In the meantime is there any kind of a workaround that I can use to change the color of the gTxtbox's color? Is there perhaps a way to change the dialog options color? I found the game.read_dialog_option_color, but nothing else. :/

SSH

RTFW!  :=

http://americangirlscouts.org/agswiki/index.php/AGS_tidbits_&_snippets

"The dialog options are drawn in the player character's talking colour. The highlighted option colour uses the GUI foreground colour if you are using a GUI TextWindow, otherwise it is hardcoded to yellow"
12

Ionias

I searched the manual and the tech forums, but forgot about searching the wiki. Doh!

Well that answers my question, thanks.

Ionias

I would love to have the ESC key “stop” any dialog if it's running. Aside from scripting all the dialogs myself, is there anyway to abort the current in-game dialog script while it's running?

Scorpiorus

Nope, there is no an easy way, I'm afraid.

The repeatedly_execute_always() function is called during dialog conversations but StopDialog() has no effect in there.

You could, probably, somehow handle it through dialog_request() but I believe it then falls under "scripting all the dialogs myself".

Ionias

Thanks, yeah it would be a great feature to have. I don't want to have to rebuild the entire dialog editor just to add that into the game however. :)

SMF spam blocked by CleanTalk