AGS v2.7 Final: Yet Another Edition

Started by Pumaman, Sat 13/11/2004 21:02:00

Previous topic - Next topic

RickJ

Quote
QuoteInstead of playing with the == operator, how about  adding a floating point function to test if a value is in a specified range.   It could return 1 if the value was within the range and 0 otherwise.  If the "min" parameter is not specified then the range is +/- max.  For example:
Good idea -- but then, as Gilbert says, it's so easy to implement yourself that I'm not sure a built-in function is necessary.
Yeah, I'm with Gilbert also.  Probably a well placed sentence or two in the manual and upgrade instructions would suffice.  I think you should mention it to illuminate confusion for the non-programmers amoung us.

Btw, are we able to create functions with optional parameters or is this restricted to built-ins?

Quote
Quoteand are enums strictly type-checked? Can I use an enum value of one enumeration as a parameter to a function that has a different enumeration type? Can you set more that one identifier to the same value in the same enumeration, i.e.
No. Yes. Yes.
The "No" answer is causing me a bit of confusion.  Hmmm.... then are enum values unique across all enum types instead of being  unique within each type?   If the former is true (i.e.  unique across all enum types) would that mean that two different enum types couldn't use the same value, for  example is the following permitted?   
enum ADEF {
   eOtherthing,
   eSomething
}

enum BDEF {
   eThis,             
   eThat,
   eOtherthing
}

Quote
Quote
And can you have static member variables, protected or otherwise?

No.
But you could make static variables in the global script and then use them for the same purpose; they just wouldn't be part of the struct.


Jet Kobayashi Zala

I think I've found another bug while trying to make a keyboard-only-controlled GUI.  When a GUI is opened, the Enter key by the number pad (keycode 13 just like the main one) does not trigger an IsKeyPressed(13), though it does when no GUI's are open.

Also, for the (sorta) new GUI objects, would it be possible to include their x and y as parameters? Such as gInventory.x and gInventory.y.

This could be handle for implementing, say, an inventory GUI that doesn't block the view of the character or that changes sides of the screen depending on where the character is.

SSH

#242
Quote from: Pumaman on Wed 05/01/2005 20:32:16
QuoteAnd can you have static protected functions?

Yes.


What is the syntax? I have tried both:

  import static protected function get_slots();

and

  import protected static function get_slots();

in my struct and neither works: it says "protected not allowed in struct" which is a misleading message anyway!

I wanted protected static variable because I want the protection on the variable and encapsulation in a struct, but the struct is actually used in an array and I only want one copy of these variables:

Code: ags

#define SGS_SLOTS_ONSCREEN    9
enum sgs_saveload_t {
  eNone, eSave, eLoad, eConfirm
};
sgs_saveload_t sgs_saveload; // I want this in the struct
int sgs_offset; // I want this in the struct
int sgs_selected_slot;  // I want this in the struct
struct sgs {
  char t[200];          // This is the string description of a save slot
  int spr;                 // This is the sprite number of a save slot
  // internal fns:
  import static  function get_slots();
  import static  function reget_slots();
  import static  function do_save();
  import static  function do_load();
  import static  function close();
  import static  function check_do_save();
  import static  function interface_click(int button);
  import static  function on_key_press(int keycode);
  import static  function repeatedly_execute();
  // external fns
  import static function Save();
  import static function Load();
};
sgs sgs_struct[(SGS_SLOTS_ONSCREEN+1)]; 


oh, that last line doesn't work either. Despite 9+1 evaluating to a constant, AGS says that array bounds must be constant  >:(

Anyway, is there another way to have my global variables inside the struct, protected? Can I nest structs?

Code: ags

struct sgs {
  char t[200];          // This is the string description of a save slot
  int spr;                 // This is the sprite number of a save slot
} 

struct sgss {
  static sgs slot[10];
  static sgs_saveload_t saveload;
  static int offset; 
  static int selected_slot; 
// imports, etc...
}


Oh, and is it possible to automatically turn off the  8) smilie in the tech forums, as it seems to code up a lot when people post code

And another question: can multiple GUI controls be set up to access the same handler function? This would be quite handy. The "this" pointer would still be set differently for each call...
EDIT: I've tried this, and it seems that you can set the same function for multiple GUI controls, but (apart from the flipping global script opening every time you do it) the "this" pointer is not set at all! It would be nice if "this" was set for GUI handler functions.

And another enum question: I presume that enums start counting at 0 by default. Can you change this by doing:

enum mye {
one = 1, two, three, four };

and have two, three, four set to 2, 3, 4?


EDIT
BUG REPORT

When I try and edit the text of a new GUI label to be longer than 25 characters, it gets truncated to 25 chars. You have said elsewhere that the limit is 200 (and I've used longer labels myself before)



12

Pumaman

QuoteYeah, I'm with Gilbert also.  Probably a well placed sentence or two in the manual and upgrade instructions would suffice.  I think you should mention it to illuminate confusion for the non-programmers amoung us.

I'll mention it in the Data Types section of the manual.

QuoteBtw, are we able to create functions with optional parameters or is this restricted to built-ins?

Yes -- in the script header just do this:

import function MyFunc(int param=5);

that will set param as an optional parameter, with a default value of 5.
Note that optional parameters only with with int and enum parameters, you can't do it with strings or floats.

QuoteThe "No" answer is causing me a bit of confusion. 

All it means is that enums work just like in C -- effectively the enum values are just #defines to their particular numbers. There's nothing to stop you passing an int to a function that expects an enum, and vice versa.

QuoteBut you could make static variables in the global script and then use them for the same purpose; they just wouldn't be part of the struct.

Yes, this is the workaround. Not very nice I know, but I did have a brief look at static member variables and it looked like it was going to be fairly hefty job to implement them.

QuoteI think I've found another bug while trying to make a keyboard-only-controlled GUI.  When a GUI is opened, the Enter key by the number pad (keycode 13 just like the main one) does not trigger an IsKeyPressed(13), though it does when no GUI's are open

I just tried this but it worked fine for me. Do you mean IsKeyPressed, or do you mean on_mouse_click? If it's the latter, it won't get called if your GUI has a text box since it steals the keypress.

QuoteAlso, for the (sorta) new GUI objects, would it be possible to include their x and y as parameters? Such as gInventory.x and gInventory.y.

Sounds reasonable to me.

Quote
What is the syntax? I have tried both:

  import static protected function get_slots();

It's
  protected import static function get_slots();

just to keep you on your toes :P
Basically, to be consistent with Java/C#, the protection level always goes first.

Quoteoh, that last line doesn't work either. Despite 9+1 evaluating to a constant, AGS says that array bounds must be constant

This isn't trivial to fix due to the way the script compiler works, I'm afraid. The workaround is to #define another constant as one higher; not perfect by any means, I concede.

Quote
Anyway, is there another way to have my global variables inside the struct, protected? Can I nest structs?

Not at the moment, no.

QuoteEDIT: I've tried this, and it seems that you can set the same function for multiple GUI controls, but (apart from the flipping global script opening every time you do it) the "this" pointer is not set at all! It would be nice if "this" was set for GUI handler functions.

I agree, that would be nice. However, it's difficult to implement this way, I'll have a think about it.

QuoteAnd another enum question: I presume that enums start counting at 0 by default. Can you change this by doing:

enum mye {
one = 1, two, three, four };

and have two, three, four set to 2, 3, 4?

Yes.

QuoteWhen I try and edit the text of a new GUI label to be longer than 25 characters, it gets truncated to 25 chars. You have said elsewhere that the limit is 200 (and I've used longer labels myself before)

Well spotted, I'll fix it.

SSH

Quote from: Pumaman on Thu 06/01/2005 18:38:10
QuoteEDIT: I've tried this, and it seems that you can set the same function for multiple GUI controls, but (apart from the flipping global script opening every time you do it) the "this" pointer is not set at all! It would be nice if "this" was set for GUI handler functions.

I agree, that would be nice. However, it's difficult to implement this way, I'll have a think about it.

Well, it can be called something else, if that helps, like game.current_button_ptr or whatever...
12

Pumaman

Yeah, the main issue is how to ensure type safety. Would just having the GUIControl* pointer be enough, or would you want to access label/button/etc-specific methods on it?

strazer

#246
Quote* Changed Character.AddInventory/LoseInventory to take the inventory item object rather than the number. For example:
player.AddInventory(iSmallKey);

You need to update the example script for InventoryItem.ID in the manual.

Edit:

QuoteObject-ised GetHotspotAt/GetCharacterAt/GetObjectAt/GetRegionAt/GetInvAt to work like GetGUIAtLocation does.

Shouldn't we rename xxxAtLocation(int x, int y) to avoid confusion with future Locations?
Also, GetCharacterAtScreen sounds more intuitive to me than GetCharacterAtLocation.

I think we should find a consistent terminology to differentiate functions expecting screen or room coordinates.

I propose:

  GetLocationName -> GetNameAtScreen
  GetLocationType -> GetTypeAtScreen
  Mouse.SaveUntilLocationChange -> Mouse.SaveUntilTypeChange

  Character.FaceLocation -> Character.FaceScreen
  GetGUIAtLocation -> GetGUIAtScreen
  GetGUIControlAtLocation -> GetGUIControlAtScreen
  ListBox.GetItemAtLocation -> ListBox.GetItemAtScreen
  GetCharacterAtLocation -> GetCharacterAtScreen
  GetHotSpotAtLocation -> GetHotSpotAtScreen
  GetInvAtLocation -> GetInvAtScreen
  GetObjectAtLocation -> GetObjectAtScreen
  GetWalkableAreaAt -> GetWalkableAreaAtScreen

  GetRegionAtLocation -> GetRegionAtLocation or GetRegionAtPosition or GetRegionAtCoordinates

Or, if we'll call Locations "Markers" instead, we have:

  GetLocationName -> GetNameAtLocation
  GetLocationType -> GetTypeAtLocation
  Mouse.SaveUntilLocationChange -> Mouse.SaveUntilTypeChange

  GetRegionAtLocation -> GetRegionAtPosition or GetRegionAtCoordinates
  GetWalkableAreaAt -> GetWalkableAreaAtLocation

Obviously less functions to rename, but, again, I think xxxAtScreen is much more intuitive.

Edit 2:

Manual -> Tutorial -> Advanced room features -> Lighting effects:
"NOTE: Light levels affect characters only - they do not affect objects" is obsolete.

Gilbert

#247
Just discovered, seems that there're problem with eRoundNearest for FloatToInt() when the number is negative (don't know about the others);
Quick Test:
Display("%d %d", FloatToInt(2.0,eRoundNearest), FloatToInt(-2.0,eRoundNearest));

Displayed text will be:
2 -1

What?2?

EDIT:
By the way, there're some limit to how many optional parameters a function can take, right?
For example the following line generates an error of 'too many arguments' while breaking it up into two lines won't crash the game:
RawPrint(0, 0, "%d %d %d %d %d %d %d", 1, 2, 3, 4, 5, 6, 7);

SSH

#248
YAY for the Room menu, at last we can edit the room script when in the areas screen, etc!


Quote from: Pumaman on Thu 06/01/2005 23:34:27
Yeah, the main issue is how to ensure type safety. Would just having the GUIControl* pointer be enough, or would you want to access label/button/etc-specific methods on it?

I'd want to run button-specific methods on it. Maybe if the handler functions can be declared with an argument, it would make the type clearer:

function myButtonHandler_Click (Button *this)...

Then when a user set a control to call a particular function, the editor could check if the function was already declared, and if it was, check that the type was the same...

Quote from: strazer on Fri 07/01/2005 01:10:08
Shouldn't we rename xxxAtLocation(int x, int y) to avoid confusion with future Locations?
Also, GetCharacterAtScreen sounds more intuitive to me than GetCharacterAtLocation.

I think we should find a consistent terminology to differentiate functions expecting screen or room coordinates.

I think "GetxxxAtXY" or "GetxxxAtCoords" is meaningful and clearest

Quote from: Pumaman on Thu 06/01/2005 18:38:10

QuoteAlso, for the (sorta) new GUI objects, would it be possible to include their x and y as parameters? Such as gInventory.x and gInventory.y.

Sounds reasonable to me.

Would it be possible to have width and height in there too, for GUIs and controls, please?



Another idea: could the syntax highlighting of the editor make deprecated function names appear in a slightly different colour?

And typo in manual ref of IsGamePaused:

if (IsGamePaudsed() == 1) UnPauseGame();

12

Jet Kobayashi Zala

QuoteI just tried this but it worked fine for me. Do you mean IsKeyPressed, or do you mean on_mouse_click? If it's the latter, it won't get called if your GUI has a text box since it steals the keypress.

I meant using IsKeyPressed inside the repeatedly_execute function.Ã,  With IsKeyPressed (13) in the repeatedly_execute, it didn't pick up the Enter key by the numpad, but does read it from the main enter. The GUI's are set to Normal except for the one that manages the cursor on the screen (set to Popup Modal).

Gilbert

But, did that GUI contain a textbox (read Pumaman's post) ? I'm not sure, but I think in that case the textbox RULEZ and ate every ENTER key pressed, so it's not even detectable with IsKeyPressed().

SSH

#251
Ummm, your earlier reply about enums was wrong, CJ. Enums default to start counting at 1, not 0!

Oh, and shouldn't SkipUntilCharacterStops be objectised?

Can we have an enum builtin for GetLocationType results?

Can the manual liust in one place the legal values for the different builtin enums?

12


Jet Kobayashi Zala

Quote from: Gilbot V7000a on Fri 07/01/2005 09:55:36
But, did that GUI contain a textbox (read Pumaman's post) ? I'm not sure, but I think in that case the textbox RULEZ and ate every ENTER key pressed, so it's not even detectable with IsKeyPressed().

Sorry, no, there are no textboxes. It's all labels and buttons.

Pumaman

QuoteYou need to update the example script for InventoryItem.ID in the manual.

The example there is using the obsolete AddInventory function, not the Character.AddInventory function. For obvious backwards compatibility reasons, I'm not changing the way the old-style AddInventory works.

QuoteShouldn't we rename xxxAtLocation(int x, int y) to avoid confusion with future Locations?
Also, GetCharacterAtScreen sounds more intuitive to me than GetCharacterAtLocation.

I think we should find a consistent terminology to differentiate functions expecting screen or room coordinates.

I agree. However, we can't just use "GetCharacterAt" because they're the old functions. Personally I don't like "AtScreen", because it doesn't really make any grammatical sense. "AtPositionOnScreen" perhaps, but then that's too long-winded.

How about "GetCharacterByPosition"?

QuoteManual -> Tutorial -> Advanced room features -> Lighting effects:
"NOTE: Light levels affect characters only - they do not affect objects" is obsolete.

Well spotted, thanks.

QuoteJust discovered, seems that there're problem with eRoundNearest for FloatToInt() when the number is negative (don't know about the others);

Good point, FloatToInt doesn't work properly with negative numbers. Well spotted, I'll get it fixed.

QuoteBy the way, there're some limit to how many optional parameters a function can take, right?

Yes, the script engine has a limit of 9 parameters in a function call. If this is too much of a problem, it can probably be increased.

QuoteI'd want to run button-specific methods on it. Maybe if the handler functions can be declared with an argument, it would make the type clearer:

function myButtonHandler_Click (Button *this)...

Yes, that was what I was thinking. The problem is how to stop you then assigning that function to a text box, for instance. I suppose the editor could do some sort of check, but it all starts to get rather involved.

QuoteI think "GetxxxAtXY" or "GetxxxAtCoords" is meaningful and clearest

'Coords' isn't a bad idea ... we should really have some way to distinguish GetRegionAt because it takes room co-ordinates, as strazer says. I'm not sure what would be best for that.

QuoteWould it be possible to have width and height in there too, for GUIs and controls, please?

I guess that would kinda go with X and Y, wouldn't it ;)

QuoteAnother idea: could the syntax highlighting of the editor make deprecated function names appear in a slightly different colour?

That's an interesting idea; it would probably involve more work than it'd be worth though. I'll think about it.

QuoteAnd typo in manual ref of IsGamePaused:

Thanks, fixed it.

QuoteIsKeyPressed (13) in the repeatedly_execute, it didn't pick up the Enter key by the numpad, but does read it from the main enter.

Ahh right; well spotted, IsKeyPressed doesn't work with the numeric keypad Enter key. I'll get it fixed.

QuoteUmmm, your earlier reply about enums was wrong, CJ. Enums default to start counting at 1, not 0!

What did I say? I can't remember! Stop confusing me! I'm just a poor old man in my rocking chair, I can't keep up with all you rowdy kids!

QuoteOh, and shouldn't SkipUntilCharacterStops be objectised?

Well, there is a wider issue of whether all functions that take a CHARID as a parameter should now take the actual character object instead; what do people think?

Quote
Can we have an enum builtin for GetLocationType results?

I suppose you can have that  ;)

QuoteCan the manual liust in one place the legal values for the different builtin enums?

How do you mean? Like a Big List of All AGS Enums?

strazer

QuoteHow about "GetCharacterByPosition"?

Nah, that sounds like the Position refers to the character's position, not the screen position.

Quote
QuoteI think "GetxxxAtXY" or "GetxxxAtCoords" is meaningful and clearest

'Coords' isn't a bad idea ... we should really have some way to distinguish GetRegionAt because it takes room co-ordinates, as strazer says. I'm not sure what would be best for that.

But XY, Coords or even Position wouldn't be any different than Location. No indication of what kind of coordinates. How about AtScreenXY and AtRoomXY?
StrLen(ScreenXY) = StrLen(Location) ;)

Jet Kobayashi Zala

Hmmm... a Big List of All Enums would be awesome. The addition of a Room Menu is handy as well.  I agree with Strazer's latest idea on the naming conventions.  OnScreenXY or AtScreenXY, along with AtRoomXY sounds clearest to me.

strazer

#257
The internal FindGUIID function is included in the autocomplete pop-up.

So are all member variables of GameState, unless that's intentional.

QuoteWell, there is a wider issue of whether all functions that take a CHARID as a parameter should now take the actual character object instead; what do people think?

Ah, now I get it. Sorry SSH, I thought you were talking about making the function a member of GameCharacter.
I'm for objectising.

RickJ

Quote
How about AtScreenXY and AtRoomXY?
If Room and Screen were objectized then you would have:
   Screen.GetNameAt(), Room.GetNameAt()

and if we are not in the mood to do anymore objectizing then we could at least fake it  like so...
   ScreenGetNameAt(), RoomGetNameAt()

I was going to stay out of this one but couldn't help myself  :=

SSH

CJ, if you just implemented overloading (and why not polymorphism while you're at it) then you wouldn't have this problem  :=
12

SMF spam blocked by CleanTalk