I have a quick simple question..



I would like to know how to reference a list.

Example

If (this is VikingSword || this is broadsword || this is mysword || Etc )

is there s way i can reference a list else where in the document instead of updating this directly? since the list could be used in more area's that would be helpful..
 
I think you mean this

public static Type[] WeapTypeA { get { return m_WeapTypeA; } }

private static readonly Type[] m_WeapTypeA= new[]
{
typeof(Axe), typeof(BattleAxe), typeof(DoubleAxe), typeof(ExecutionersAxe), typeof(GargishAxe),
typeof(GargishBattleAxe), typeof(GuardianAxe), typeof(HeavyOrnateAxe), typeof(JadeWarAxe),
typeof(LargeBattleAxe), typeof(Pickaxe), typeof(SingingAxe), typeof(ThunderingAxe), typeof(TwoHandedAxe),
typeof(WarAxe),typeof(WarFork),typeof(ShortSpear)
};

I can't remember the exact "phrasing" to use but I believe it was

if( WeapTypeA contains this )
 
I think you mean this

public static Type[] WeapTypeA { get { return m_WeapTypeA; } }

private static readonly Type[] m_WeapTypeA= new[]
{
typeof(Axe), typeof(BattleAxe), typeof(DoubleAxe), typeof(ExecutionersAxe), typeof(GargishAxe),
typeof(GargishBattleAxe), typeof(GuardianAxe), typeof(HeavyOrnateAxe), typeof(JadeWarAxe),
typeof(LargeBattleAxe), typeof(Pickaxe), typeof(SingingAxe), typeof(ThunderingAxe), typeof(TwoHandedAxe),
typeof(WarAxe),typeof(WarFork),typeof(ShortSpear)
};

I can't remember the exact "phrasing" to use but I believe it was

if( WeapTypeA contains this )

This is a great start.

It's not so obvious but a simple 'contains' check won't be enough to implement the logic applied by an 'is' check in the original 'if' statement.

'is' checks Type hierarchy, so we need to devise a way to do that with the list too.

Code:
private static Type[] _Types = new[] { typeof(Longsword), typeof(BaseRanged), typeof(PlateChest) };

public static bool IsValidType( Type test )
{
	foreach ( var type in _Types )
	{
		if ( test == type || test.IsSubClassOf( type ) ) // 'is' functionality: ( test is type )
			return true;
	}

	return false;
}

Usage:
Code:
var validType = IsValidType( item.GetType( ) );

if ( isValidType )
{
	// true
}
 
Thanks guys! :) that got me what I needed, its easier to reference a list then having to add in all that extra code...
 
A rule I've adopted is that any time I find myself repeating the same line of code multiple times, I figure out a way to turn it into one line of code or at least send to another method to do the base of the work.
 
I inserted the code (looks correct from what what put above) and it kicked back this error.

Code:
Errors:
+ BaseClasses/BaseArmor.cs:
    CS1061: Line 28: 'System.Type' does not contain a definition for 'IsSubClassOf' and no extension method 'IsSubClassOf' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
 
it would help if we could see your code

this may help you

Code:
public static BulkGenericType Classify(BODType deedType, Type itemType)
        {
            if (deedType == BODType.Tailor)
            {
if (itemType == null || itemType.IsSubclassOf(typeof(BaseArmor)) || itemType.IsSubclassOf(typeof(BaseShoes)))

as for the code I posted earlier, this is how I used it in a OnWeaponHit method
if( WeapTypeA.Contains (weapon.GetType()))
 
Awesome, ty :) I fixed the typo, for usage i had to change item to this, to refrence baseweapon and it worked.

Code:
            var validType = IsValidType( this.GetType( ) );
    
            if ( validType )
            {
                from.SendMessage( "LETS TEST THIS OUT!!!!" );
            }
            from.CheckStatTimers();
 
Back