Making an c++ function ?

So here’s what I want to do:
When a certain someone wants to add a new weapon to the game then they go to a .txt file then write something like addweapon(name,min_dmg,max_dmg,cost,ammo), which would look something like addweapon(“M4A1”, 12, 15, 1000, 30) I tried to make a code for it but I don’t know much about C++ :frowning:
Here’s what i’ve done so far :blush: :

void addweapon(char name, int min_dmg, int max_dmg, int cost, int ammo)

then I don’t know what else to do lol, help please.

Bump :frowning:

I don’t understand what you’re trying to do.

A person wanted to add a new weapon to the game, to do that he must get a .txt file then type in the addweapon function, my problem is… how will I do it.
Like when someone types in the .txt file.

addweapon("M4A1", 12, 15, 3000, 35)

Then when the game starts the function will be executed then a “new” object will be created based on the function’s arguments, in this case the object will be named “M4A1” then new object variables will be added to it.
I seen this in one of the examples in GDevelop:

[code]#include “TextObject/TextObject.h” //but do not forget extensions includes

//Simple function changing scene background color.
//The function is declared in Test.h and called by Scene 2
void MyFunction(RuntimeScene & scene)
scene.SetBackgroundColor(240, 100,100);

//Another function manipulating objects this time.
void MyFunction2(std::vector<RuntimeObject*> & objectsList)
//Changing the positions of objects
for(unsigned int i = 0;i<objectsList.size();++i)

//Manipulating the text objects more specifically thanks to GetSpecificObjects
std::vector<RuntimeTextObject*> textObjects = GetSpecificObjects<RuntimeTextObject>(objectsList);
for(unsigned int i = 0;i<textObjects.size();++i)
    textObjects[i]->SetString("Hi, my X coordinate was changed to be 50.");

So if there is objectList and GetSpecificObjects there then there must also be a object.Create or something?
But I don’t know how to do what I want to do, so I need help :question:

You got it all wrong. A C++ function can only be used with C++, not in a .txt file. You can’t let the user type a function call in a txt and launch it : that’s not possible (or it would need to be compiled before).

So if i change the .txt to .cpp then it can work? and to put it in to the game will this work too?

#include "FILE_NAME"

where “FILE_NAME” is the name of the file.

No, because it will not be compiled (or the updated txt file won’t be).

Aw, so there is no way to achieve what I want to do? :neutral_face:

Though I’m a bit curious, how can I add a variable to an already existing object through C++ code ? :slight_smile: