AGS v2.7 Final: Yet Another Edition

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

Previous topic - Next topic

Scorpiorus

Ok, here is a test game where struct members list doesn't seem to pop up after the this keyword followed by a dot:

// main global script file

// TYPE_MyCharacter Implementation:
function TYPE_MyCharacter::Init(CHARID id)Ã,  {

this.
}

http://www.geocities.com/scorpiorus82/oos_test.zip (copy & paste)
It's right at the top of the main global script.

Tested with AGS v2.7 beta 6.

Pumaman

Thanks for that, it's a bit of an odd bug in the autocomplete. I'll get it fixed.

Pumaman

Right, beta 7 is now up.

The mouse functions have been object-ised, and that ends the objectisation that I'm going to do for 2.7. All the functions that have not yet been changed are not going to be changed, unless anyone can think of a good reason to.

Anyway, the new names for the mouse functions are still negotiable -- I've tried to rename them to make them better reflect what they do, but let me know if you disagree.

what are static member functions?

static member functions are functions which belong to a struct, but which are not part of an actual instance of a struct. In effect, they are global functions.

What's the point? Purely organisational. A static function could just as well be a normal global function but being grouped into a struct allows you to organise related functions better.

Example:
script header:
struct Blah {
  import static function mystaticfunc();
};

global script:
static function Blah::mystaticfunc() {
}

usage:
Blah.mystaticfunc();

static functions do NOT have a "this" pointer since they do not belong to an instance.

what are protected members?

A protected member is only accessible to member functions within the struct, and cannot be used from outside. For example:

script header:
struct Blah {
  protected int data;

  import function SetData(int newdata) ;
};

global script:
function Blah::SetData(int newdata) {
  this.data = newdata;
}

usage:
Blah bla;
bla.data = 5;  // <--- ILLEGAL, WON'T COMPILE
bla.SetData(5);  // <--- Use this instead

Rui 'Trovatore' Pires

QuoteWell, this may well be the last beta before Christmas ... I hope you've all got the Santa hats out!

You said this for the previous beta. ::) You see, Chris, this is why we love you.

Quote* Setting the list box selected bkgrnd colour to 0 now makes it transparent.
* Fixed game load & restart crash bug in beta 6.

Yee-haw! Party time for me! ;D
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Jet Kobayashi Zala

#144
I'm not sure if this is just me or not, but whenever I change like the speech style and the new "Enforce object-based scripting" the settings are either a) not saved, or b) when loaded, the checkbox and listbox don't get set.

I'm not sure if this is a bug that others are getting or just my whacky computer acting up again.

Oh, and Chris, thanks for all the crazy work you've done for AGS!Ã,  If I were a girl, I'd have your baby.Ã,  ... Well... maybe...

Rui 'Trovatore' Pires

QuoteFor buttons, you can also find out whether the left or right mouse button was clicked.

How, exactly?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

QuoteI'm not sure if this is just me or not, but whenever I change like the speech style and the new "Enforce object-based scripting" the settings are either a) not saved, or b) when loaded, the checkbox and listbox don't get set.

I just did a quick check and it worked fine. Are you sure this is happening? You did save the game after changing the settings, right?

QuoteEDIT: I've also sometimes had a problem that when I try to compile, I'll get like "Undefined Token 'InterfaceOn' " for a GUIOn in the keypress script.Ã,  Also, when I create a new game using the "Default Game" Template, I get an undefined token for "LEFT". I assume that's because of the new changes with the mouse?

If you tick Enforce Object-based Scripting, then these functins are no longer supported. "GUIOn" has been replaced by "gGuiname.Visible = true;" and "LEFT" has been replaced by eMouseLeft.

QuoteHow, exactly?

Add a handler for the button (ie. double-click the "Click" entry at the bottom of the button's properties). The handler will be created with an "int button" parameter, which tells you whcih mouse button was used.

Rui 'Trovatore' Pires

Ah, lovely. Thanks a bunch, I didn't know I could use that check here.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Jet Kobayashi Zala

#148
QuoteI just did a quick check and it worked fine. Are you sure this is happening? You did save the game after changing the settings, right?

I just tried it again, and it worked for me too, though I know I did save it before.

QuoteIf you tick Enforce Object-based Scripting, then these functins are no longer supported. "GUIOn" has been replaced by "gGuiname.Visible = true;" and "LEFT" has been replaced by eMouseLeft.

Heh. Yeah, I noticed that right after I posted that. Sorry. -_-

RickJ

#149
mouse.x, mouse.y
Maybe these should be properties instead of global vars even though it's subtle distinction?

*** Edit ***

Quote

* Added support for static member functions.
* Added support for protected member variables/functions.
How to use these?  Is it documented yet? 



strazer

Rick, look a few posts above you... ;)

RickJ

Thanks Strazer, found the explanation.  I guess I just got over-excited.   One remaining question;  is it possible to have static member data and protected member functions?  I'll try some experiments to find out....  :=

CJ, Thanks for the AGS 2.7 Christmas present. 

...  Merry Christmas All ...

Jet Kobayashi Zala

Jet here again. Sorry to bug you, but I THINK I might have found another bug. I've included a sample game so you could check it out, but from what I can gather, this seems to be the issue: If you declare an array of a user-defined structures, in this case,

Code: ags
char_data pc[10];


And you set values out of order:

Code: ags
pc[0].SetName("Chris");
pc[2].SetName("Scorpiorus");
pc[1].SetName("Radiant");


Then it nulls out the value of element immediately before it. The sample game's example works just like this. The way it is now with pc[ARTEA] before the pc[RUNT] assignments, it works fine, but if you were to reverse them (put the RUNT assignments, then the ARTEA ones), it seems to null the ARTEA ones out. When testing the game, use the '+' to open a menu, and '0' (zero) to close it and you'll see what I mean. Code-wise, I think it should all be correct.

http://jetkobayashizala.kicks-ass.net/cb.zip

And don't forget: Merry Christmas, Happy Holidays, and all that good stuff to all of you awesome AGS'ers out there! Especially Chris!

strazer

When updating one of my demo games from Beta 4 to Beta 7, the editor didn't complain about
  NewRoomEx(2, 10, player.y);
in the "Walk off right screen edge" interaction in one of the rooms (with object-based scripting enforced).
The game compiled fine. When walking off the right edge of the screen, it changed rooms, but the player character was nowhere to be seen. It didn't crash.
I had an NPC face him, and he faced downwards...?
I updated the line, and when I rebuilt all rooms, the editor correctly complained about the other similar line in the other room. Updated both, now it works.
With the original line restored and object-based scripting NOT enforced, everything works fine as well.
Hm, I don't know what exactly my point is, maybe a note about remembering to rebuild all room files prior to testing when a game from an earlier version is loaded into the editor?

And how about making MODE_LOOK, MODE_USEINV etc. enums too?

In another demo game, I get this:

QuoteAn exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x0044A974 ; program pointer is +1004, ACI version 2.70.807, gtags (0,0)

Can you tell from this what the problem could be?

Stickieee

Quote from: Pumaman on Sun 12/12/2004 18:23:36
All GUI controls now have a "Script name" property, which allows you to give them a VB-style "lstSaveGames" or "btnCancel" type name.
Then, in the script you can do stuff like:
lstSaveGames.AddItem("Jibble");
rather than
ListBoxAdd(3, 6, "Jibble");

This is way too cool to be true. It makes the code so much cleaner to read. However I had a bit of a problem with them GUIs. After five minutes of converting my old scripts into this oo-thing, I came upon

if (GetGuiAt(mouse.x, mouse.y) != 1) { do_stuff(); }
which I tried to change into GetGuiAtLocation. I also changed the 1 into GuiName, or something. Ags however said that I can't use != to compare two GUIs (I'm sorry, I don't have the exact error message with me here at uni) and I tried a bit more and I couldn't use == either. So I used the oh-so-cool .ID bit 'cause you can compare ints. And it worked, until there was no gui under mouse, ie. getguiatlocation gives null which doesn't have .ID. Or at least the engine crashed saying something about pointers and all.

I worked through it with if and else, but still, isn't a bit annoying not to be able to compare GUIs? Or did I just do something wrong?
EXPLOSION

Pumaman

#155
Quotemouse.x, mouse.y
Maybe these should be properties instead of global vars even though it's subtle distinction?

Perhaps, and that same argument could be applied to character[].x/y ... I'm not convinced of the need to change it.

Quoteis it possible to have static member data and protected member functions?

No and yes, respectively.Ã,  :)

QuoteSorry to bug you, but I THINK I might have found another bug. I've included a sample game so you could check it out, but from what I can gather, this seems to be the issue:

I just tried to download your sample game, but the link didn't work. Without knowing the code behind the struct it's hard for me to replicate the problem.

Any chance you could just post the code for that struct and its functions?

QuoteWhen updating one of my demo games from Beta 4 to Beta 7, the editor didn't complain about
  NewRoomEx(2, 10, player.y);
in the "Walk off right screen edge" interaction in one of the rooms

Ah, yes this is a problem with using "player". Because it's now a pointer to the current player character, the rooms need to be re-compiled in order to work with it. I'll add that to the 2.7 upgrade docs when the time comes.

QuoteIn another demo game, I get this:
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x0044A974 ; program pointer is +1004, ACI version 2.70.807, gtags (0,0)

Can you tell from this what the problem could be?

Hmm no, that's strange -- any chance you could upload the game that causes the problem?

Quoteif (GetGuiAt(mouse.x, mouse.y) != 1) { do_stuff(); }
which I tried to change into GetGuiAtLocation. I also changed the 1 into GuiName, or something. Ags however said that I can't use != to compare two GUIs (I'm sorry, I don't have the exact error message with me here at uni) and I tried a bit more and I couldn't use == either. So I used the oh-so-cool .ID bit 'cause you can compare ints. And it worked, until there was no gui under mouse, ie. getguiatlocation gives null which doesn't have .ID. Or at least the engine crashed saying something about pointers and all.

GUI *theGui = GetGUIAtLocation(mouse.x, mouse.y);
if (theGui != null) {
  if (theGui.ID == INVENTORY) {
    Display("On the inventory GUI");
  }
}

replace INVENTORY with the GUI ID, obviosuly.

I appreciate this is slightly more involved than the old GetGUIAt code, but it does add flexibility to the script language.

strazer

#156
Quote from: Pumaman link=topic=17697.msg222907#msg222907
QuoteIn another demo game, I get this:
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x0044A974 ; program pointer is +1004, ACI version 2.70.807, gtags (0,0)

Can you tell from this what the problem could be?

Hmm no, that's strange -- any chance you could upload the game that causes the problem?

Oh, it may be worth noting that I'm using the current beta with Wine (a Windows API wrapper) under Linux. I've pm'd you the game download location anyway.

Edit:

Haha, figures. I just found out I forgot to update the room file in this demo as well...
Sorry for wasting your time. Works now.

Pumaman

Hehe yep, that'll be it.

I think it'd probably be a good idea if AGS automatically recompiles all room files if you upgrade from a pre-2.7 version.


Jet Kobayashi Zala

Alrighty, here's the code. It's kinda big, sorry. :/

Here's the global header:
Code: ags

// Stats
#define STAT_STRENGTH	0
#define STAT_AGILITY	1
#define STAT_VITALITY	2
#define STAT_MAGIC	3
#define STAT_SPIRIT	4
#define STAT_LUCK	5

#define HP	0
#define MAX_HP	1
#define MP	0
#define MAX_MP	1

// EQ Slots
#define EQ_WEAPON	0
#define EQ_HEAD		1
#define EQ_BODY		2
#define EQ_ARMS		3
#define EQ_ACCESSORY	4

// Elements
#define ELEMENT_FIRE	0
#define ELEMENT_AIR	1
#define ELEMENT_WATER	2
#define ELEMENT_EARTH	3
#define ELEMENT_VOID	4

// Item Types

#define ITEM_GENERAL 0
#define ITEM_WEAPONÃ,  1
#define ITEM_ARMORÃ,  Ã, 2
#define ITEM_MONEYÃ,  Ã, 3
#define ITEM_KEYIYEM 4

// ------ keyboard control ------
#define DIR_DISTANCEÃ,  Ã, 10000
#define DIR_DOWN_LEFTÃ,  1
#define DIR_DOWNÃ,  Ã,  Ã,  Ã, 2
#define DIR_DOWN_RIGHT 3
#define DIR_LEFTÃ,  Ã,  Ã,  Ã, 4
#define DIR_STOPÃ,  Ã,  Ã,  Ã, 5
#define DIR_RIGHTÃ,  Ã,  Ã,  6
#define DIR_UP_LEFTÃ,  Ã,  7
#define DIR_UPÃ,  Ã,  Ã,  Ã,  Ã, 8
#define DIR_UP_RIGHTÃ,  Ã, 9

struct game_data {
Ã,  int party[10];	// Stores order of party members by charID
Ã,  long money;		// Stores money; Score will be used for something else
Ã,  long time;		// Stores time in seconds. Can be converted later
};

struct char_data {
Ã,  char name[15];	// Name of the character
Ã,  char title[20];	// Character's job title
Ã,  short basestats[6];	// "Natural" stats before eq
Ã,  short stats[6];	// Stats after equipment and such
Ã,  short hp[2];		// Character Hit Points
Ã,  short mp[2];		// Character Magic Points
Ã,  short level;		// Character Level
Ã,  long exp;		// Character Experience
Ã,  short element;	// Character's Elemental Affinity
Ã,  short eq[5];		// Stores index number of item in corresponding eq slot
Ã,  
Ã,  import function SetName (string newName);
Ã,  import function SetTitle (string newTitle);

};


The global declarations in the main script file:
Code: ags

char_data pc[10];
game_data cb;

function char_data::SetName(string newName) {
Ã,  StrCopy(this.name,Ã,  newName);
}

function char_data::SetTitle(string newTitle) {
Ã,  StrCopy(this.title,Ã,  newTitle);
}


And then game_start where the members are initialized:
Code: ags

function game_start() {
Ã,  // called when the game starts, before the first room is loaded
Ã,  pc[SLADE].SetName("Slade Azurus");
Ã,  pc[SLADE].SetTitle("Knight of Illus");
Ã,  pc[SLADE].level = 17;
Ã,  pc[SLADE].hp[HP] = 100;
Ã,  pc[SLADE].hp[MAX_HP] = 150;
Ã,  pc[SLADE].mp[MP] = 10;
Ã,  pc[SLADE].mp[MAX_MP] = 1250;

Ã,  pc[ARTEA].SetName("Artea Scotsen");
Ã,  pc[ARTEA].SetTitle("Treasure Hunter");
Ã,  pc[ARTEA].level = 24;
Ã,  pc[ARTEA].hp[HP] = 200;
Ã,  pc[ARTEA].hp[MAX_HP] = 250;
Ã,  pc[ARTEA].mp[MP] = 150;
Ã,  pc[ARTEA].mp[MAX_MP] = 167;

Ã,  pc[RUNT].SetName("Runt");
Ã,  pc[RUNT].SetTitle("Pickpocket");
Ã,  pc[RUNT].level = 5;
Ã,  pc[RUNT].hp[HP] = 20;
Ã,  pc[RUNT].hp[MAX_HP] = 20;
Ã,  pc[RUNT].mp[MP] = 0;
Ã,  pc[RUNT].mp[MAX_MP] = 0;
Ã,  
Ã,  int i = 0;
Ã,  while (i < 10) {
Ã,  Ã,  cb.party[i] = -1;
Ã,  Ã,  i++;
Ã,  }

Ã,  cb.party[0] = SLADE;
Ã,  cb.party[1] = ARTEA;
Ã,  cb.party[2] = RUNT;
Ã,  
Ã,  cb.money = 5000;
Ã,  
Ã,  mouse.Visible = false;
Ã,  // ------ keyboard control ------
Ã,  PrevDirection = DIR_STOP;
//Ã,  SetGlobalInt (4, 1);
Ã,  
}


SLADE, ARTEA, and RUNT are all character script names (ID's), so I use them as the array index holder. SLADE = 0, RUNT = 1, and ARTEA = 2. They are initialized and output in a menu later. With the above code, the pc[2] (pc[ARTEA]) ends up blank, but if you switch them and put pc[RUNT] first, it works fine. Oh, and if you need the sample game, the link should work now. If not, I can always e-mail it or something.

SMF spam blocked by CleanTalk