UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

[Script Help] How would i call a GSC function from a String

broken avatar :(
Created 11 years ago
by Deleted User
0 Members and 1 Guest are viewing this topic.
5,326 views
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
Basicly how would i call multiple files with the same function inside of them in the same folder without having to do something like this

Code Snippet
Plaintext
thread maps\<FOLDER>\test::test();
thread maps\<FOLDER>\test1::test();
thread maps\<FOLDER>\test2::test();
thread maps\<FOLDER>\test3::test();
thread maps\<FOLDER>\test4::test();
thread maps\<FOLDER>\test5::test();
thread maps\<FOLDER>\test6::test();

could i do something like this

Code Snippet
Plaintext
functions = [];
functions[functions.size] = "test";
functions[functions.size] = "test1";
functions[functions.size] = "test2";
functions[functions.size] = "test3";
functions[functions.size] = "test4";
functions[functions.size] = "test5";
functions[functions.size] = "test6";
keys = GetArrayKeys(functions);

for(i = 0; i < keys.size; i++)
{
key = keys[i];
thread "maps/<FOLDER>/" + key + "::test"();
wait .5;
}
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
Signature
Let's keep this thread on topic from here on in. -DBZ

+1 to off-topic reply -DBZ

lmao. Too funny.

Goliath Script Placer: http://ugx-mods.com/forum/index.php/topic,11234.msg125257/topicseen.html#new

"...Christ, people. Learn C, instead of just stringing random characters
together until it compiles (with warnings)..."

-Linus Torvalds
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
By using the pointer function.

Code Snippet
Plaintext
	level.common_settings = :: common_settings;

Code Snippet
Plaintext
[[level.common_settings]]();

The variable will have the value of that function in that specific script.
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 6 years ago
Posts
6,875
Respect
Forum Rank
Immortal
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
Signature
If you want scripts / features made for you, then contact me by PM or email / skype etc
it will cost you tho so if you have no intention of reciprocating don't even waste my time ;)
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
By using the pointer function.

Code Snippet
Plaintext
	level.common_settings = :: common_settings;

Code Snippet
Plaintext
[[level.common_settings]]();

The variable will have the value of that function in that specific script.
^ I use this method to link functions to my perks in my scripts

it takes either "undefined" or "::functionname"

then later i use

Code Snippet
Plaintext
if ( isDefined( perk.functionname ) )
    [[perk.functionname]]( arg1, arg2, etc );
Last Edit: June 01, 2015, 05:09:18 am by Harry Bo21
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
By using the pointer function.

Code Snippet
Plaintext
	level.common_settings = :: common_settings;

Code Snippet
Plaintext
[[level.common_settings]]();

The variable will have the value of that function in that specific script.
i know about the doing the above but that would mean i know what the file is called i want to do something like this
if this is not possible just tell me and i can try to change my system to work with the pointer

Code Snippet
Plaintext
//I wont call other people will who want to add functions to what im trying to make (and im trying to keep between me and a few close friends)
addFunction(name, shortName)
{
if(!IsDefined(level.stuff))
level.stuff= [];
level.stuff[shortName] = name;
}

and later on do something like this
Code Snippet
Plaintext
callAll()
{
keys = GetArrayKeys(level.stuff);

for(i = 0; i < keys.size; i++)
{
name = level.stuff[keys[i]];
thread [["maps\" + name + "::init"]]();
wait .5;
}
}

this is mod code so far sorry if it wont work
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 6 years ago
Posts
6,875
Respect
Forum Rank
Immortal
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
dont think so, but not 100% sure

this would work i think

Code Snippet
Plaintext
variable0 = \maps\_yourscript::init;
variable1 = \maps\_yourscript::init;

level thread [[ variable0 ]]();
level thread [[ variable1 ]]();

or

Code Snippet
Plaintext
variable = [];
variable[ 0 ] = \maps\_yourscript::init;
variable[ 1 ] = \maps\_yourscript::init;

for ( i = 0; i < variable.size; i++)
{
    level thread [[ variable[ i ] ]]();
}

Im not even sure about that coz your trying to reference scripts from other scripts, which may complicate things.
Last Edit: June 01, 2015, 05:23:52 am by Harry Bo21
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
I'm not sure what you mean by not knowing what GSC file you want to call. You should know that. But if you want to call a random function you could try doing something like this:

Code Snippet
Plaintext
example()
{
level.func[0] = maps\_exampleOne::init;
level.func[1] = maps\_exampleTwo::init;
level.func[2] = maps\_exampleThree::init;

[[level.func[randomint(level.func.size)]]]();

}

Might not be 100% on the syntax but you get the idea.

Last Edit: June 01, 2015, 05:24:44 am by daedra descent
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
I'm not sure what you mean by not knowing what GSC file you want to call. You should know that. But if you want to call a random function you could try doing something like this:

Code Snippet
Plaintext
example()
{
level.func[0] = maps\_exampleOne::init;
level.func[1] = maps\_exampleTwo::init;
level.func[2] = maps\_exampleThree::init;

[[level.func[randomint(level.func.size)]]]();

}

Might not be 100% on the syntax but you get the idea.

by not knowing the GSC file i want to call i mean i want to get a function from a name i give it in an array but the array doesnot have the function save in it

Code Snippet
Plaintext
names = [];
names[0] = "test";

//the GSC file would be this
maps\test::test();

//but if i change names[0] to hi
names[0] = "hi";

//the GSC file will change to be come
maps\hi::test()
do you now see what im trying to do?!?
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 6 years ago
Posts
6,875
Respect
Forum Rank
Immortal
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
i think he means so that if you will always be calling a function you define, but the script its in can be different depending on the use

I think he means so he can call inits from multiple scripts, using one function and just a arg to define the script to call said function from like

load_function( script, function )
{
    script/function();
}

I think I understand what hes trying to do, but certainly seems like the "harder" way of going about it

The way your currently doing it could eventually lead to "missing function" errors unless you remember to perfectly tune it - which will ultimately be harder than just storing in a key based array

Id do like DD said and try to make it fit with pointers rather than attempting strings. The only way i can see you using strings is if you put them in a array and calling it by key
Last Edit: June 01, 2015, 05:32:07 am by Harry Bo21
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
i think he means so that if you will always be calling a function you define, but the script its in can be different depending on the use

I think I understand what hes trying to do, but certainly seems like the "harder" way of going about it

Id do like DD said and try to make it fit with pointers rather than attempting strings. The only way i can see you using strings is if you but them in a array and calling it by key

for now ill just make my system work with pointers
it would be simpler with pointers and easier to understand but would be easier if i didn't need to use pointers

what im basing this off of is Java's Class.forName();

in which you can get a loaded Class (Script) from the given Package(location) and call functions from that Class
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 6 years ago
Posts
6,875
Respect
Forum Rank
Immortal
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
use this

in your induvidual scripts, add them to a level array instead

Code Snippet
Plaintext
// IN THE SCRIPT THAT SHOULD CONTAIN THE FUNCTION
level.this_scripts_functions = [];
level.this_scripts_functions[ "init" ] = ::init;

// IN THE SCRIPT YOUR CALLING IT FROM
[[level.this_scripts_functions[ "init"] ]]();

You could even use a multidimensional array

Code Snippet
Plaintext
// In Each script
if ( !isDefined( level.script_functions ) )
    level.script_functions = [];

level.script_functions[ "_zombiemode_perks" ] = [];
level.script_functions[ "_zombiemode_perks" ][ "init" ] = ::init;
level.script_functions[ "_zombiemode_perks" ][ "update" ] = ::update;

// Another script
if ( !isDefined( level.script_functions ) )
    level.script_functions = [];

level.script_functions[ "_zombiemode_weapons" ] = [];
level.script_functions[ "_zombiemode_weapons" ][ "init" ] = ::init;
level.script_functions[ "_zombiemode_weapons" ][ "update" ] = ::update;

// In the script you will call it from
[[ level.script_functions[ "_zombiemode_weapons" ][ "init" ] ]]();
[[ level.script_functions[ "_zombiemode_perks" ][ "update" ] ]]();

Last Edit: June 01, 2015, 05:47:01 am by Harry Bo21
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
use this

in your induvidual scripts, add them to a level array instead

Code Snippet
Plaintext
// IN THE SCRIPT THAT SHOULD CONTAIN THE FUNCTION
level.this_scripts_functions = [];
level.this_scripts_functions[ "init" ] = ::init;

// IN THE SCRIPT YOUR CALLING IT FROM
[[level.this_scripts_functions[ "init"] ]]();

If all he wants to do is init the function init() in each script then this would be less efficient because your creating a variable for each script instead of just using an index of a single array variable.
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 6 years ago
Posts
6,875
Respect
Forum Rank
Immortal
Primary Group
Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social LinksHarryBo000[email protected]HarryBo21
You misunderstood me, one array in total, across all scripts, add to that "from" each script

DDs right, youll end up exceeding script variable limits and stuff eventually
Last Edit: June 01, 2015, 05:48:40 am by Harry Bo21
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(

You could even use a multidimensional array

Code Snippet
Plaintext
// In Each script
if ( !isDefined( level.script_functions ) )
    level.script_functions = [];

level.script_functions[ "_zombiemode_perks" ] = [];
level.script_functions[ "_zombiemode_perks" ][ "init" ] = ::init;

// Another script
if ( !isDefined( level.script_functions ) )
    level.script_functions = [];

level.script_functions[ "_zombiemode_weapons" ] = [];
level.script_functions[ "_zombiemode_weapons" ][ "init" ] = ::init;

// In the script you will call it from
[[level.script_functions[ "_zombiemode_weapons"][ "init" ] ]]();
[[level.script_functions[ "_zombiemode_perks"][ "init" ] ]]();

this is what i want to do but where 'init' i want it to be in one line pretty much
and instead of passing the fucntion i want to just pass the file name and the function will be passed later

Code Snippet
Plaintext
level.script_functions[0] = "file_name";

//then do
level thread [["maps\" + level.script_functions[0] + "::init"]]();

but im just gonna go with pointers since that seems like the easier way and more well known way of doing it

 
Loading ...