Weird objGetStaticData problem

These are old bug reports that have been closed.
Locked
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

I am overriding objCanInstallItem to allow some custom device mass checks. (previously I overwrote all installdeviceprep functions, but this should be cleaner).

(objGetStaticData theShip 'maxDeviceMass') is breaking with

Code: Select all

Function name expected [theShip] ### (objGetStaticData theShip "maxDeviceMass") ###
(objGetStaticData gPlayership 'maxDeviceMass') isn't.

theShip is a passed parameter. The function is called from rpgInstallDevicePrep in RPGCode.xml with targetObj as the corresponding argument and targetObj is compared for equality with gPlayership so they must be the same data type.

I can conceive of no non-bug reason that objGetStaticData should fail with a passed argument but not with a global variable of the same type.

And I need to be able to get the staticdata off the passed spaceobject rather than hard coding because installation functions can now be called on autons.
Literally is the new Figuratively
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Atarlost wrote:I am overriding objCanInstallItem to allow some custom device mass checks. (previously I overwrote all installdeviceprep functions, but this should be cleaner).

(objGetStaticData theShip 'maxDeviceMass') is breaking with

Code: Select all

Function name expected [theShip] ### (objGetStaticData theShip "maxDeviceMass") ###
(objGetStaticData gPlayership 'maxDeviceMass') isn't.

theShip is a passed parameter. The function is called from rpgInstallDevicePrep in RPGCode.xml with targetObj as the corresponding argument and targetObj is compared for equality with gPlayership so they must be the same data type.

I can conceive of no non-bug reason that objGetStaticData should fail with a passed argument but not with a global variable of the same type.

And I need to be able to get the staticdata off the passed spaceobject rather than hard coding because installation functions can now be called on autons.
Very likely an engine bug. Maybe objGetStaticData has been redefined somehow? Please send me the full extension and I can put the debugger on it.
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Thanks for sending the files. Here is what I found:

1. In Atarlost_Utility.xml line 471: There is a extra closing paren, so the setq looks like it has 3 parameters (which it complains about).

2. The same line complains that singleMax is not an identifier (string). This is because:

Code: Select all

(if (objGetStaticData theShip singleMax) ...
singleMax is a number, not a string. I'm not sure what your intent is here. Do you mean (if (not singleMax)... ?

3. Line 470 has an extra quote at the end of maxDeviceMass:

Code: Select all

(objGetStaticData theShip 'maxDeviceMass')

should be:

(objGetStaticData theShip 'maxDeviceMass)
This should have raised an error, so I fixed the code to do so.

4. Line 512 is the culprit:

Code: Select all

(CobjCanInstallItem (theShip theDevice))
Notice that it's trying to call a function named "theShip". Unfortunately, due to a bug in the parser, it did not generate an error there but only much later, which is why you got the strange error that you did. I've fixed that bug so the parser outputs the proper error.

5. Unfortunately, once I fix those bugs there is a fundamental problem that I cannot fix easily:

Code: Select all

(setq CobjCanInstallItem objCanInstallItem)
The above call sets CobjCanInstallItem to objCanInstallItem. Your intent is clearly to remember the original value of the function. Unfortunately, due to new code in the betas, <Globals> gets run multiple times in a game. This is to handle the case where two extensions define the same global. We need to make sure that the selected extensions get executed just before the game is created/loaded.

The problem is that the second time through, CobjCanInstallItem gets set to the redefined objCanInstallItem; this leads to an infinite recursion (that eventually crashes).

Ideally, I would fix this by resetting the global state every time we start a new game. I tried to do that but it got more complicated than I expected, so I'm going to defer that until later.

In the next release, I've implemented <CanInstallItem> on ship classes. I hope you'll be able to use that instead of redefining the functions.

Either way, thanks for trying this--I've found lots of good bugs in the engine.

EDIT: Try the following:

Code: Select all

(if (iserror CobjCanInstallItem)
   (setq CobjCanInstallItem objCanInstallItem)
   )
That should define CobjCanInstallItem only if it is NOT already defined. That will avoid the infinite recursion.
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Somehow I think I sent you the wrong version of the file, though I can't imagine how since I haven't been saving old versions. None of those errors except the issue with redefining the function are in my copy, but things seem to be working now so it was apparently the issue on my side. Thanks.
Literally is the new Figuratively
Locked