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 9119773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:28:32+00:00 2026-06-17T05:28:32+00:00

I’m creating a 2D RPG game engine in C++ with Allegro. I’ve reached the

  • 0

I’m creating a 2D RPG game engine in C++ with Allegro. I’ve reached the point in which i need to implement a scripting system. So, my poblem is this one:

I have a struct called Event. Inside this struct there is a function pointer, which points to the function that i want to execute when the event is fired. So, here’s an example:

struct Event {
    //...
    void (*func)(Player*, void*);
    //...
}

Now, to create an event i have this function:

Event* Events::register_event_source(int x, int y, std::string name, Player* player, void (*func)(Player*, void*));

So, to use it i just need to create a function with this signature:

void test_event(Player* p, void* data)
{
    //Do something cool here
}

and then register an event source, giving the address to that function:

//...
Player* player = new Player(0, 0);
//...
Event* evt = Events::register_event_source(10, 10, "test event", player, &test_event);
//Eventually set some data for the event
evt->set_data(new std::string("Just some test data"));

In this way, when the player goes over the assigned spot (in this case x = 10, y = 10) the event will fire, executing any code in the test_event function.

Now, my question is: is it possible to do, or at least to get close to, this process at runtime?? …i would need to create the function (in this case “test_event”) at runtime, but i did some research, and i think what i understood is that it is not really possible to create functions at runtime.
So, which approach should i go for?? …I know it is an abstract question…but i really don’t know how to approach this problem.

Thanks in advice for any help! and sorry for my bad explaining abilities…English is not my language!

  • 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-06-17T05:28:33+00:00Added an answer on June 17, 2026 at 5:28 am

    If I understand correctly what you are trying to express, you are writing a scripting engine that interprets some logics built at run-time into a string, and this should determine what to do on Player and data. If so, I can imagine you should have a function like

    void InterpretScriptCode(Player* p, void* data, string const& code)
    

    or something equivalent that interprets and execute the logics described in code on p and data.

    Then, you can use std::bind and std::function to encapsulate a call to your scripting engine:

    // Header <functional> needs to be included, and a proper "using namespace"
    // directive must be present for bringing placeholders _1 and _2 into scope
    
    std::function<void(Player*, void*)> fxn = std::bind(
        &InterpretScriptCode,
         _1,
         _2,
        "int x = 0; ... blah blah" // this should be your run-time generated script
        );
    

    And pass fxn in input to your register_event_source() function.

    Btw, you might be interested in using Boost.Signals/Boost.Signals2 for realizing event registration/handling.

    If you are not using C++11, you can use boost::bind and boost::function instead of std::bind and std::function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words

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.