So far here is mine ...
public void GetPlayer() // get player is just a normal method that will be called somewhere else..fyi
{
foreach (IPlayer playr in Game.GetPlayers())
{
IPlayerStatistics dmg1 = null;
float dmg = dmg1.TotalDamageTaken;
Game.ShowPopupMessage(dmg.ToString());
}
}
now my problem here is in the line ..IPlayerStatistic dmg1 = null; ..... if i were to run this in the game, i get an error msg. this error message .....
Script Error
Error in method 'Profiles(TriggerArgs)' in map script. See the exception for more details:
/* btw the reason it says in method 'Profiles(TriggerArgs)" is because the method GetPlayer() was called in a Method Profiles (TriggerArgs)*/
--- Exception ---
Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at SFDScript.GameScript.GetPlayer()
at SFDScript.GameScript.Profiles(TriggerArgs pro)
now my problem is if i don't use null to initialize "IPlayerStatistic dmg1", then i cant write any line of code having to do with this statement ... "dm1.TotalDamageTaken" because i get the error code CS0165 .. which is an error code in visual studio meaning the dmg1 was never initialized. Additionally, i tried doing this dmg = dmg.TotalDamageTaken; ... but it said it cant convert from float to IPlayerStatistics since IPlayerStatics is a type and i doubt it has a parse method... so any one of you guys got a workaround for this. It would be great if you answer would be an improvement on my code but i don't mind if you have to create a whole new code. Thanks
This forum is locked and will eventually go offline. If you have feedback to share you can find us in our Discord channel "MythoLogic Interactive" https://discord.gg/nECKnbT7gk
Forum rules
Forum rules
A script to get the total amount of dmg a player has taken
Forum rules
By using the forum you agree to the following rules.
By using the forum you agree to the following rules.
-
jamisco
- Superfighter

- Posts: 67
- Joined: Sun Nov 06, 2016 11:34 pm
- Title: Da God
- SFD Account: Jamisco
- SFD Alias: Jamisco
- Started SFD: either late 2015 or early 2016
- Location: Somewhere in the east of the United states
- Gender:
- Age: 105
A script to get the total amount of dmg a player has taken
0 x
Is it better to be feared or respected... please, is it too much to ask for both?
- ShutDownMan
- Fighter

- Posts: 32
- Joined: Sat Mar 19, 2016 7:17 pm
- Title: Yeah, science!
- SFD Alias: ShutDownMan, Devil Shut
- Started SFD: 1.2.something
- Location: Hu3, Brazil
- Gender:
- Age: 26
- Contact:
You can't get a property of a null value...
if:
IPlayerStatistics dmg1 = null;
then
float dmg = dmg1.TotalDamageTaken;
is the same as saying:
float dmg = null.TotalDamageTaken;
the fix is simple just replace your "IPlayerStatistics dmg1 = null;" with:
IPlayerStatistics dmg1 = playr.Statistics;
(try to use proper variable naming)
if:
IPlayerStatistics dmg1 = null;
then
float dmg = dmg1.TotalDamageTaken;
is the same as saying:
float dmg = null.TotalDamageTaken;
the fix is simple just replace your "IPlayerStatistics dmg1 = null;" with:
IPlayerStatistics dmg1 = playr.Statistics;
(try to use proper variable naming)
1 x
~ShutDownMan