Andrew, thanks for the help.
I thought I had already tried
MySprite sprite(texture);
and gotten an error saying that MySprite didn’t have any constructors that took a Texture argument, but I might have had something mistyped somewhere. I’ll try that again.
As for inherited calls: TADS3 is also multiple inheritance; as far as I know inherited
calls all of the constructors of all the superclasses (or parent versions of any other method) in the correct order of declaration as far as what overrides what.
So let’s say that we have
class MyClass : ClassA, ClassB {
// do I need to explicitly call constructors of every superclass here?
//MySprite() : ClassA(), ClassB() { init } ?
Also, if ClassA or B require arguments, does MySprite()
need to contain matching args between its parentheses and then call the parent constructors after the colon with those args?
Then, modify
… are there other ways of accomplishing this in C++? It feels pretty indispensable for programming a text adventure to work the way you want, while still getting the library to do all the grunt work. If you don’t know the TADS lingo, here’s an example:
// This is in a library source file:
class Thing: object
bulk = 1
// a hundred other attributes and methods
;
class Actor: Thing
bulk = 10
isHim = nil
isHer = nil // an Actor could be an animal or even a group:
// don't presume any gender
// many more Thing overrides and unique properties
;
///////// now this is in your own game source
class MyOwnClass: Thing
// stuff
;
modify Thing
bulk = 5 // we have a different system in mind than the library
// default, so we want a different default
;
modify Actor
/* our game is entirely composed of female actors: set the default
so we don't have to specify this for every instance */
isHer = true
// our bulk will still == 10 because Actor overrides Thing, even with
// the modify statement
;
The example shows how it works, although changing a few simple default attributes isn’t all that important. It’s much more important for when you modify methods of key action processes, where places scattered all over the library will be calling that method. You’re literally changing how the library works to suit your needs, without having to alter the original source files, because the changes are only compiled into your game.
One last issue, if you can help! In TADS3 I am used to statically declaring instances of game world objects; typically you don’t need to use new
or constructors, and each object has a global identifier (if you want it), and can be referenced from anywhere in game code.
//top-level statement
magicWardrobe: EntryPortal, Container, Thing
// stuff
;
//now 'magicWardrobe' is a symbol than can be used anywhere in
//game code: a reference to the statically created object
Now, without really having a good understanding of how a VM works or how TADS source compares to Python or C++, I assume that these objects are sort of like global variables? Yet I hear that global variables are not good coding practice, so this leads me to ask:
What is the correct C++ way to instantiate lots of small objects? Is it supposed to be done in the main
function? Where should they be stored? How do you refer to them (let’s say we’re talking about sprites again) from anywhere else in your code? After learning TADS first, Python really bugged me by not being able to refer to other instance objects in the program by simply using a unique identifier: it was always self.abc
or self.parent.otherchild.attributeStoringAnObject
.
Thanks again!