C
C#2y ago
izzint

Public Static Variable Not Updating in other scripts

in script A, I define a variable public static string fooC;, I update it in a function,
// this script is called "A"
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
// LoggerInstance.Msg(sceneName);

fooC = sceneName;

// for whatever reason this is what i want it to be.
LoggerInstance.Msg(RPCname);


// this calls the stored
discManage.GetActivityManager().UpdateActivity(fooB.RPCloader, (result) =>
{

if (result == Discord.Result.Ok)
{
LoggerInstance.Msg("BLRP Loaded!");

}
else
{
LoggerInstance.Error("Error Loading BLRP");
}
});

}
// this script is called "A"
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
// LoggerInstance.Msg(sceneName);

fooC = sceneName;

// for whatever reason this is what i want it to be.
LoggerInstance.Msg(RPCname);


// this calls the stored
discManage.GetActivityManager().UpdateActivity(fooB.RPCloader, (result) =>
{

if (result == Discord.Result.Ok)
{
LoggerInstance.Msg("BLRP Loaded!");

}
else
{
LoggerInstance.Error("Error Loading BLRP");
}
});

}
and then I try to access it in another script,
public static class fooB
{
public static Discord.Activity RPCloader = new Discord.Activity
{
State = fooA.FooC,

Timestamps =
{
Start = 4
},

Assets =
{
LargeImage = "loadinglarge",
SmallImage = "smalloading"

},


};
public static class fooB
{
public static Discord.Activity RPCloader = new Discord.Activity
{
State = fooA.FooC,

Timestamps =
{
Start = 4
},

Assets =
{
LargeImage = "loadinglarge",
SmallImage = "smalloading"

},


};
but the variable is just at the default "RPCname", im sorry if this is really bad formating, im new to asking with help, and i can't find anything on google to help me. I don't know if this breaks OOP or not
15 Replies
Steak
Steak2y ago
where did u access the fooC ?
izzint
izzint2y ago
I accessed it from another script its like creating a new field i think? Im thinking that when the other script asks for fooC it's too early
Steak
Steak2y ago
was it this part?
Steak
Steak2y ago
izzint
izzint2y ago
yea sorry about my code, I still have lots to learn about readability
Steak
Steak2y ago
it is probably too early just re-create a new discord obj
izzint
izzint2y ago
i could probably make a while loop or something untill the value is not null, but that might cause a whole lot of stuff
Steak
Steak2y ago
do you want State is the sceneName ?
izzint
izzint2y ago
what could that do?
Steak
Steak2y ago
no, i mean do want the Discord State is equal to the scene name?
izzint
izzint2y ago
yea
Steak
Steak2y ago
maybe just create static function to get new RPC loader
izzint
izzint2y ago
oh yea, good idea
Steak
Steak2y ago
or rather than creating a new one get the stored RPC Loader reference, but set the State from a parameter
izzint
izzint2y ago
Thanks a bunch @Steak ! I think i figured it out Im just gonna run a test in a moment to see Fixed! Thanks :)
Want results from more Discord servers?
Add your server
More Posts