Author Topic: MODULE: BackwardsCompatible v1.01  (Read 4261 times)

SSH

  • Flying round the world at the speed of haggis
    • I can help with scripting
    • SSH worked on one or more games that won an AGS Award!
    •  
    • SSH worked on one or more games that was nominated for an AGS Award!
MODULE: BackwardsCompatible v1.01
« on: 24 Oct 2006, 15:23 »
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

« Last Edit: 16 Mar 2007, 11:43 by SSH »

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    • Kweepa worked on one or more games that won an AGS Award!
    •  
    • Kweepa worked on one or more games that was nominated for an AGS Award!
Re: MODULE: BackwardsCompatible v1.0
« Reply #1 on: 24 Oct 2006, 15:44 »
Wow, awesome idea!
Still waiting for Purity of the Surf II

Candle

  • Truly Hated
Re: MODULE: BackwardsCompatible v1.0
« Reply #2 on: 27 Oct 2006, 03:50 »
Thanks SSH, man you just keep them coming don't ya.
You ever sleep? lol

The_Creep

  • Later...in the emergency room
Re: MODULE: BackwardsCompatible v1.0
« Reply #3 on: 23 Feb 2007, 22:33 »
 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?

Re: MODULE: BackwardsCompatible v1.0
« Reply #4 on: 26 Feb 2007, 16:24 »
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

  • 100101101010b
    • Scorpiorus worked on one or more games that won an AGS Award!
    •  
    • Scorpiorus worked on one or more games that was nominated for an AGS Award!
Re: MODULE: BackwardsCompatible v1.0
« Reply #5 on: 26 Feb 2007, 17:29 »
Yes the same here, it actually returns the number of inventory items.

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: MODULE: BackwardsCompatible v1.0
« Reply #6 on: 26 Feb 2007, 18:58 »
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: [Select]
#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: [Select]
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: [Select]
// 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.
« Last Edit: 26 Feb 2007, 19:19 by monkey_05_06 »

Pumaman

  • Creator of AGS
  • Administrator
  • Mittens King
  • I sense danger.
    • Lifetime Achievement Award Winner
    • Pumaman worked on one or more games that won an AGS Award!
    •  
    • Pumaman worked on one or more games that was nominated for an AGS Award!
Re: MODULE: BackwardsCompatible v1.0
« Reply #7 on: 26 Feb 2007, 19:50 »
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

  • Flying round the world at the speed of haggis
    • I can help with scripting
    • SSH worked on one or more games that won an AGS Award!
    •  
    • SSH worked on one or more games that was nominated for an AGS Award!
Re: MODULE: BackwardsCompatible v1.01
« Reply #8 on: 16 Mar 2007, 11:44 »
Can you try the latest version with whatever it was you found the problem with, strazer, to make sure I fixed it right, please?

Re: MODULE: BackwardsCompatible v1.01
« Reply #9 on: 16 Mar 2007, 12:26 »
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?