Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 621613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:53:38+00:00 2026-05-13T18:53:38+00:00

I’ve got way too much information to work with , so for now I’ll

  • 0

I’ve got way too much information to work with, so for now I’ll consider this question answered until I can sort it all out and decide on the final implementation! Thanks a ton gf and Simon Buchan. I wish I could accept both of your answers, since they’re both definite possibilities!

Additional / Revised Conceptual Information as suggested:

What I am aiming to do;

I am making a game. In this game every object used is an instance of the DOBJ class. The TUR class extends the DOBJ class. The SHO class extends the TUR class.

Each TUR class has an array of SHO’s stored in it’s SHOARR array. Each SHO instance needs to be given a set of instructions.

I know for a fact I could make 1000’s of different SHO classes that have their instructions set during construction.

However, considering I will have so many different acting SHO instances, I was interested in another way to pass a set of instructions. Through the contruction of the SHO would be the ideal.

The instructions I am attempting to pass to each SHO are simple if statements;

if(frame > 64) { rotation += 4; };
if(state == 0 && frame < 32) { xs = 12; ys = 12; state = 1; };

Original question

Migration from ActionScript3.0 to C++ is proving to be a trial indeed. Thanks to those who have answered my questions thus far and also to those who opened stackoverflow in the first place. Onto the question… (TL;DR near the bottom to get straight to the question)

I’m attempting to apply the same logic that I could apply in AS3.0 to my project in C++ and it’s just not going very well.

In AS3.0 I was used to slapping any and every datatype into an Array. It made things pretty simple. Now that I’ve run into C++ dev, I realized that I can’t exactly do that anymore.

So now I’m stuck with this problem of rewriting a little AI system in a new language, where the driving point of the system isn’t even compatible!

Here’s an example of a piece of the code I was writing in AS3.0;

AI[NUM][1]( OBJ, AI[NUM][2], AI[NUM][3] );

AI being an array, NUM being an integer, OBJ being an instance of a class.

This line obviously called the function in the second element of the first array in the main array with the arguments being a class in which to perform the function on, whatever was in the third element of the first array of the main array, and likewise the fourth element.

In this case;

AI[NUM][1] would be a function
AI[NUM][2] would be a variable
AI[NUM][3] would be a number

Generally, my AI was run on calling a function to change or compare the variable with a number.

An example would be;

CompareST( someObject, "x", 500 );

and return true if someObject’s x variable was smaller than (ST) 500.

The AI array itself was just filled with arrays of calls similar to this.

Quite new to C++ I had no idea how to go about this, so I did a bit of searching and reading of many different websites and came to the conclusion that I should look into function pointers.

However, after reading a bit into them, I’ve come to the conclusion that it won’t help me realize my goal. While it did help me call functions like I wanted to call them, it doesn’t help me stack different datatypes into one large array of arrays.

TL;DR

EDIT++:

What I need for each object is a set of instructions to be checked every frame. However, for each instance of the class, the instructions have to be different.

I plan on having a LOT of different instances, so making a class for each one is unreasonable.

Thus, I needed a way to pass a set of instructions to each one through it’s constructor and read + execute them at any time their think() function is called.

My ultimate goal (aside from finding out about a better way to go about this) would be to be able to have an array of function calls, like;

A[n][0]( O, A[n][1], A[n][2] );

Where;
O is the instance the function is altering
A[n][0] is a function (Equality or Comparison)
A[n][1] is the variable, eg; “x”, O["x"] (or a pointer to that variable in the case of C++)
A[n][2] is the value to alter the variable by, or compare it to.

And I’m not sure how I would rewrite this into C++, or alter it to work in another way.

Aftermath / Additional Information

What I’m actually aiming to do is be able to give an object a set of instructions at the time of it’s creation, through the constructor. For example upon creation give an object instructions to wait 64 frames, and then rotate in the opposite direction, would have been something like this;

t.AI = [ [ 1, AIF.CompareET, "STATE", 0, AIF.CompareGT, "FRAME", 64, 0, AIF.EqualityAT, "baseRotation", 180, AIF.EqualityET, "STATE", 1 ] ];

In pseudocode;

(The 1 in the array denotes how to read the rest of the array, in this case everything before the odd 0 [ The one that comes after 64 ] is a comparison. If any of those fail, anything after the 0 will not be looked at )

Compare STATE is equal to (ET) 0, if true
Compare FRAME is greather than (GT) 64, if true
Add 180 to (AT) baseRotation, Set STATE equal to 1

Sorry that this turned out really long. I hope it’s understandable, and I’m not asking something stupidly difficult to explain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:53:39+00:00Added an answer on May 13, 2026 at 6:53 pm

    You can store functions using function pointers or functors. Variant types though are not natively supported by C++, you have to use custom solutions there.

    One possibility would be to use Boost.Any (or better, Boost.Variant if you only use a fixed set of types):

    typedef void (*Function)(Object*, const std::string&, boost::any&);
    std::vector<Function> functions;
    

    Given some function:

    void f(Object* obj, const std::string& name, boost::any& value) {
        // ...
    }
    

    you could store and call it similar to your example:

    functions.push_back(&f);
    functions[0](obj, "x", boost::any(500));
    

    To utilize a declarative syntax, there are three options that come to my mind:

    • you use a similar approach and have central “interpreter” function, e.g. based on a switch (don’t forget to switch to integers or pointers-to-members instead of strings if you need performance)
    • you invent your own language and generate C++ code from description files
    • you compose function objects in a declarative way

    To do composition, you could use Boost.Bind or something like custom objects that represent operations:

    struct Operation {
        virtual ~Operation() {}
        virtual bool operator()(Object&) = 0;
    };    
    
    template<class T>
    struct GreaterThen : Operation {
        typedef T Object::*Member;
        Member member;
        const T value;
        CompareGT(Member member, const T& value) : member(member), value(value) {}
        bool operator()(Object& obj) { return (obj.*member > value); }
    };
    
    template<class T>
    struct SetTo : Operation {
        typedef T Object::*member;
        Member member;
        const T value;
        SetTo(Member member, const T& value) : member(member), value(value) {}
        bool operator()(Object& obj) { obj.*member = value; return true; }
    };
    

    Now we can build operation lists:

    typedef std::vector<Operation*> OpList;
    OpList operation;
    operations.push_back(new GreaterThen<int>(&Object::Frame, 64));
    operations.push_back(new SetTo<int>(&Object::State, 1));
    

    We can use helper functions to avoid having to specify the template types:

    template<class T>
    Operation* opGreaterThen(T Object::*mem, const T& val) {
        return new GreaterThen<T>(mem, val);
    }
    

    Assuming a similar helper for SetTo and using Boost.Assign the above becomes:

    OpList operations = boost::assign::list_of
        (opGreaterThen(&Object::Frame, 64)) 
        (opSetTo      (&Object::State,  1));
    

    Executing the operations becomes the following then:

    OpList::iterator it = operation.begin();
    for( ; it != operations.end(); ++it) {
        Operation& op = *it; // just for readability
        if(!op(someObject)) break; // stop if operation returns false        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 333k
  • Answers 333k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ok, this was actually pretty straightforward: import pkg sub_modules =… May 14, 2026 at 3:14 am
  • Editorial Team
    Editorial Team added an answer You could check whether HttpContext.Current returns null or not. Technically,… May 14, 2026 at 3:14 am
  • Editorial Team
    Editorial Team added an answer It's not difficult to do this. To display the p… May 14, 2026 at 3:14 am

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.