MODULE: BackwardsCompatible v1.01

Started by SSH, Tue 24/10/2006 15:23:47

Previous topic - Next topic

SSH

Ever tried using a module or template in AGS 2.72 and got warnings about GetGameParameter or RunDialog being undefined? BackwardsCompatible fixes that without any changes to the existing module. Wahey!

It works in any AGS version but there ain't much point in using it in anything except AGS 2.72.

Please let me know if there are any more obsoleted functions that need supporting here.

BackwardsCompatible documentation
Download BackwardsCompatible
wiki article

12

Kweepa

Still waiting for Purity of the Surf II

Candle

Thanks SSH, man you just keep them coming don't ya.
You ever sleep? lol

The_Creep

 Thanks SSH, This module saved me (I think) from a real headache.My game actually compiles now (whereas previosly it did not) but before it even runs it crashes presenting me with the error:

Error: run_rep_Exec: error -6 (Error: Array index out of bounds (Index: 4, 0..3) in CharacterRegionSounds (line 56)
)Running Function "Repeatedly_Execute_Always"

Any Ideas? I'm completely at a loss, its been almost a year since I tried to understand ags code, and its always changing so kinda hard to keep up
If you had nothing left, would you risk it all to change everything?

strazer

It may be a problem with Wine, since I have to run AGS v2.72 through that, but when I create a game with 4 characters and put this in game_start:

  Display("%d", GetGameParameter(GP_NUMCHARACTERS, 0, 0, 0)); // old-style

with this module, it returns 3 instead of 4, while

  Display("%d", Game.CharacterCount); // new-style

returns the correct 4.
But the BackwardsCompatible module also simply tries to return Game.CharacterCount.

Can anyone confirm this? What's going on? Very strange.

Scorpiorus

Yes the same here, it actually returns the number of inventory items.

monkey0506

#6
Although I'm not CJ I have found the problem...

My initial take was to just check which value of parameter was actually causing the function to return via Display statements. None of them ran. Not even the one at the end of the script saying "Return value undefined". So I threw in one at the top. Still nothing.

I figured the issue probably had something to do with the way the enums were set up (though at this point I couldn't figure out why my Display-s weren't working), so I took a look at ROOMEDIT.CLB, which defines the values you've placed in GameParameter as:

Code: ags
#define GP_SPRITEWIDTH   1
#define GP_SPRITEHEIGHT  2
#define GP_NUMLOOPS      3
#define GP_NUMFRAMES     4
#define GP_ISRUNNEXTLOOP 5
#define GP_FRAMESPEED    6
#define GP_FRAMEIMAGE    7
#define GP_FRAMESOUND    8
#define GP_NUMGUIS       9
#define GP_NUMOBJECTS    10
#define GP_NUMCHARACTERS 11
#define GP_NUMINVITEMS   12
#define GP_ISFRAMEFLIPPED 13


Whereas your definition for the enum is:

Code: ags
enum GameParameter { GP_SPRITEWIDTH, GP_SPRITEHEIGHT, GP_NUMLOOPS,
	GP_NUMFRAMES, GP_ISRUNNEXTLOOP, GP_FRAMESPEED, GP_FRAMEIMAGE,
	GP_FRAMESOUND, GP_ISFRAMEFLIPPED, GP_NUMGUIS, GP_NUMOBJECTS,
	GP_NUMCHARACTERS, GP_NUMINVITEMS } ;


You might not have noticed, but GP_ISFRAMEFLIPPED is the last in the built-in definitions, while it is 9th (of 13) in your definitions. The way enums work, even if you don't explicitly assign them a value, the enumerated types are implicitly assigned values, in the order they are defined.

I found two methods of fixing this issue:

Code: ags
// method 1:
enum GameParameter { GP_SPRITEWIDTH=1, GP_SPRITEHEIGHT=2, GP_NUMLOOPS=3,
	GP_NUMFRAMES=4, GP_ISRUNNEXTLOOP=5, GP_FRAMESPEED=6, GP_FRAMEIMAGE=7,
	GP_FRAMESOUND=8, GP_ISFRAMEFLIPPED=13, GP_NUMGUIS=9, GP_NUMOBJECTS=10,
	GP_NUMCHARACTERS=11, GP_NUMINVITEMS=12 } ;

// method 2:
enum GameParameter { GP_SPRITEWIDTH, GP_SPRITEHEIGHT, GP_NUMLOOPS,
	GP_NUMFRAMES, GP_ISRUNNEXTLOOP, GP_FRAMESPEED, GP_FRAMEIMAGE,
	GP_FRAMESOUND, GP_NUMGUIS, GP_NUMOBJECTS,
	GP_NUMCHARACTERS, GP_NUMINVITEMS, GP_ISFRAMEFLIPPED } ;


Also I've discovered why none of my Display statements were apparently being run.

Although GetGameParameter is imported in ROOMEDIT.CLB if and only if STRICT has not been defined (i.e., you have not enforced object-based scripting), the function is not actually defined in ROOMEDIT.CLB. In short, although you're importing GetGameParameter in the module header, and even exporting it from your module script (though this isn't necessary for functions), the function being imported is not the one defined by your module.

The function that your statement imports is actually the built-in version of the function. If you don't believe me...just try commenting out your version of the function in the module script. You'd expect an "Unresolved import 'GetGameParameter'" error. But you don't get one. If you'd already fixed your enums, you'll notice that the function runs perfectly as expected.

Otherwise GP_ISFRAMEFLIPPED, GP_NUMGUIS, GP_NUMOBJECTS, GP_NUMCHARACTERS, and GP_NUMINVITEMS would all return unexpected results (GP_ISFRAMEFLIPPED would return GP_NUMGUIS, GP_NUMOBJECTS would return GP_NUMCHARACTERS, etc.) due to their improper definitions (as the built-in function expects the built-in values, not your enumerated values).

All-in-all not the most obvious reasons for these unexpected results. But honestly SSH...can't you debug your modules yourself instead of crying to CJ the instant something goes wrong? :P

[EDIT:]

In fact...it would appear that aside from providing imports for these built-in functions...your module doesn't actually do anything. Your custom defined versions of all these functions are completely ignored.

That's not to say that this module isn't useful. Because it's nice to be able to upgrade AGS versions without worrying about your scripts breaking. Just saying that it doesn't really work the way you might expect.

Pumaman

Well discovered monkey_05_06, you are of course correct.

The AGS engine still exports all the old-style functions, the only thing that happens when "Enforce object-based scripting" is ticked is that they are removed from the script header so that your script won't compile.

So in fact, all your BackwardsCompatible module needs to do is provide a script header with the appropriate import declarations in it ;)

SSH

Can you try the latest version with whatever it was you found the problem with, strazer, to make sure I fixed it right, please?
12

strazer

Yep, thanks, now it seems to work.
Although I rather liked the enum idea. You could have kept it using monkey's first method, no?

SMF spam blocked by CleanTalk