Original Post
🔒 Locked
Calling a function/variable by name ? string ?
Advertisement
The short answer : you can''t.
The long answer : you can''t, short of parsing the symbol table yourself, or finding some API function (like GetProcAddress for Win32 DLLs or dlsym for Unix dsos) that support it. Then you''ll get into the wonderful world of name mangling...
What you can do, is to manually keep a table (e.g. std::map) matching function names to function addresses, and use it to call the functions.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
The long answer : you can''t, short of parsing the symbol table yourself, or finding some API function (like GetProcAddress for Win32 DLLs or dlsym for Unix dsos) that support it. Then you''ll get into the wonderful world of name mangling...
What you can do, is to manually keep a table (e.g. std::map) matching function names to function addresses, and use it to call the functions.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
Well actually I haven
NPC Level[0].People[0] SetPosition 10,0,0
NPC Level[0].People[1] SetPosition 0,0,5
PlayCameraScript Scripts\\Intro.scp
PlayMusic Music\\Intro.wav
//This is probably what I think of it but it may also include :
Talk NPC Level[0].People //which will have it
t tryed yet but i want to make Game Scripts and the best way seems to be the calling of a function by name or some switch if it doesnt work ...it should look like this : Intro.gscNPC Level[0].People[0] SetPosition 10,0,0
NPC Level[0].People[1] SetPosition 0,0,5
PlayCameraScript Scripts\\Intro.scp
PlayMusic Music\\Intro.wav
//This is probably what I think of it but it may also include :
Talk NPC Level[0].People //which will have it
s own "speech"
GiveItem Potion
GiveGold 100
MovePlayer Player1 1,0,5
SetPlayerAnimation Animations\\GoThere.ani
And the list can continue...Although this is the first time Ive tryed to see how they should be done...
I havent had to much success with passing information to functions/variables in the way you explained. I just made another function that recieves all the information in my own format and it passes the information in the proper converted format to your other functions/variables. The problem is that you will have to write quite a bit more code that includes all the functions and variables.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement