Since my server is not AOS, propeties are not displayed so i had to add manually the next thing:

Code:
//////////////////ADDED BY MED/////////////////////
        public override void OnSingleClick( Mobile from )
        {
            if(m_Completed)
            {
                string CompletedText ;
                bool ascii = true;
CompletedText = String.Concat("Task Completed [{0} {1}]", this.m_AmountToGather, m_MaterialName);
int hue = (1169);
PrivateOverheadMessage(MessageType.Label, hue, ascii, CompletedText /* m_AmountToGather, m_MaterialName */, from.NetState);
           
        }
            else
            {
                string ObtainedText ;
                bool ascii = true;
ObtainedText = String.Concat( "{0} / {1} {2} Obtained", m_AmountGathered, m_AmountToGather, m_MaterialName );
int hue = (24);
PrivateOverheadMessage(MessageType.Label, hue, ascii,  ObtainedText/*m_AmountGathered, m_AmountToGather , m_MaterialName*/, from.NetState);
            }
        }
        ///////////////////////////////////
And this is the way it looks in game, boooo:

resourstring.png

Thanks
 
String.Concat, wouldn't it be String.Format?
[doublepost=1477955054][/doublepost]Furthermore, shortening it to that:
Code:
public override void OnSingleClick( Mobile from )
{
    base.OnSingleClick(from);

    string description = m_Completed ? String.Format("Task Completed [{0} {1}]", this.m_AmountToGather, m_MaterialName) : String.Format( "{0} / {1} {2} Obtained", m_AmountGathered, m_AmountToGather, m_MaterialName );
    PrivateOverheadMessage(MessageType.Label, m_Completed ? 1169 : 24, true, description, from.NetState);
}

- It would be more compact.
- Much less variable declarations.
- Calls the base method on Item.

The downside is that using the:
Code:
(boolStuff) ? trueThing : falseThing;
Can be confusing to use if not used to.

Some references:
https://msdn.microsoft.com/en-ca/library/zakwfxx4(v=vs.100).aspx
https://msdn.microsoft.com/en-us/library/ty67wk28.aspx
https://www.dotnetperls.com/ternary
 
Last edited:
to give another example

player.SendMessage( ( 1 < 2 ) ? "One is less than 2" : "One is magically more than 2!");

breaks down like this

if( 1 < 2 )
player.SendMessage( "One is less than 2");
else
player.SendMessage( "One is magically more than 2!");

there isn't necessarily any problem with writing it out the long way, as long as you get all your if/else if/else statements written correctly
 
For my part i tend to repeat as less code as possible, and avoiding un-ncessary indenting to have a better maintenability over time.
The biggest downside with that is that you need to read it all to know what it does instead of following a specific conditional line, but atleast it gives a better look over the concept in it's whole rather than a portion.

Ultimately it depends on the programmation level of the coder and his/her preferences.
Also, when you start something out of the blue, always use the if/else way at first, so you can refactor quickly and optimizing at the very end, it greatly helps the learning process.
 
also, String.Format is the correct thing to use. It's what will format the string to replace {0} with the property in a string
String.Concat basically just takes two strings and adds them together in a format you specify.


Code:
//////////////////ADDED BY MED/////////////////////
        public override void OnSingleClick( Mobile from )
        {
            if(m_Completed)
            {
                string CompletedText ;
                bool ascii = true;
CompletedText = String.Format("Task Completed [{0} {1}]", this.m_AmountToGather, m_MaterialName);
int hue = (1169);
PrivateOverheadMessage(MessageType.Label, hue, ascii, CompletedText /* m_AmountToGather, m_MaterialName */, from.NetState);
          
        }
            else
            {
                string ObtainedText ;
                bool ascii = true;
ObtainedText = String.Format( "{0} / {1} {2} Obtained", m_AmountGathered, m_AmountToGather, m_MaterialName );
int hue = (24);
PrivateOverheadMessage(MessageType.Label, hue, ascii,  ObtainedText/*m_AmountGathered, m_AmountToGather , m_MaterialName*/, from.NetState);
            }
        }
 
Back