RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Getting the base of all skills

[Solved]
I am trying to get the base of all skills by using foreach (Skill skill in pm.Skills)
But it returns all the skills null
Thank you for your time.
I did spend a few hours searching the forums to resolve this problem.

Code:
            foreach (Skill skill in pm.Skills)
            {
                if (skill == null) //Debug
                {
                    Console.WriteLine("ERROR: classic-skill");
                    continue;
                }
 
                exp += skill.Base * Settings.EXP_PER_POINT_ONE;
            }

Edit: I got some help and am able to achieve what i wanted to do with this

Code:
            Skills skills = who.Skills;
            for ( int i = 0; i < skills.Length; ++i )
                    {
                        Skill skill = skills[i];
                        exp += skill.Base * Settings.EXP_PER_POINT_ONE;           
                    }

Thanks a lot curious viewers :p
 

daat99

Moderator
Staff member
What happens if you try:
C#:
foreach ( Skill skill in who.Skills )
{
    exp += skill.Base * Settings.EXP_PER_POINT_ONE;
}
 
daat99 - I did try that and that (skill == null) causing the server to crash if players logged in.
(without the debug in place)Edit: Could also have been the way the datatype was being returned but I'm not sure.
I made some edits to my op removing part of the script from the post because I got it to work with the code under the edit. I just left the section that was giving me problems and my solution. Is there any reason i should not be using my solution code?
Thanks for replying!
 

daat99

Moderator
Staff member
There is no real reason on why you shouldn't use your solution but I can't figure out why your solution isn't crashing if the foreach loop does.
Can you make it crash in debug mode and post the crash log please?
 
Can you make it crash in debug mode and post the crash log please?
While the debug is in place the server does not crash. It writes ERROR: classic-skill to the console numerous times.
This is the log of the crash with the debug commented out
Code:
Server Crash Report
===================
 
RunUO Version 2.2, Build 4940.27340
Operating System: Microsoft Windows NT 6.1.7601 Service Pack 1
.NET Framework: 4.0.30319.17929
Time: 11/14/2013 9:03:35 AM
Mobiles: 1
Items: 9
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
  at LevelCore.LevelSystem.classicLevel(Mobile who)
  at LevelCore.LevelSystem.display(Mobile who)
  at Server.Mobiles.PlayerMobile.GetProperties(ObjectPropertyList list)
  at Server.Mobile.get_PropertyList()
  at Server.Mobile.get_OPLPacket()
  at Server.Mobile.SendEverything()
  at Server.Mobile.set_Map(Map value)
  at Server.Mobile.set_NetState(NetState value)
  at Server.Network.PacketHandlers.PlayCharacter(NetState state, PacketReader pvSrc)
  at Server.Network.MessagePump.HandleReceive(NetState ns)
  at Server.Network.MessagePump.Slice()
  at Server.Core.Main(String[] args)
 
Clients:
- Count: 1
+ 127.0.0.1: (account = -) (mobile = 0x1 '-')
Again, thank you for taking interest!
If you need to look at entire scripts i would prefer we do that through PM.
 

daat99

Moderator
Staff member
Please run the server in debug mode without your null check code.
If you don't know how to run the server in debug mode than please look in the FAQ section.

Debug crash file will tell us more.
 
I've decided to help myself by seeing if I can solve this problem without help. Should have stuck to my guns before i posted this thread. Practice makes perfect and while i may never be perfect at C# I can get better. If i solve it this will be the first place i post.
Thank you daat99 for being awesome and trying to lend a helping hand.
 

daat99

Moderator
Staff member
You should really run your server in debug mode if you are having crashes.
The debug crash logs will tell you exactly what crashes and not just a hint like the normal crash logs.
 
I did run it in debug mode after you suggested to do so. with the information that provided i can code in better debugging to see if i can find the real reason it didn't work.
 

daat99

Moderator
Staff member
OK, if you want any further assistance or just someone else to look into it feel free to post the debug crash log with the latest code.
 
Top