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!

A namespace does not directly contain members such as fields

gzero

Wanderer
A namespace does not directly contain members such as fields

Hello, I've a new private shard Im working on and beginning to learn to read C#. I have been able to compile Wolfs armor scripts, but anything else I have tried to compile (and thus far I only have tried simple weapons and such) gives me this same error A namespace does not directly contain members such as fields or methods. (Line 1, comumn 1) I have tried tutorials, comparing with scripts that have worked, comparing with the scripts in runuo, and searching these forums like mad. I am not seeing any difference in the scripts introduction; nothing seems out of place to my untrained eye. Has anyone any ideas as to what the problem could be? Thank-you ?
 

gzero

Wanderer
This a smaple of a script I am trying to compile -Wolf's ElvishBow



using System;
using Server;
using Server.Network;
using Server.Items;

namespace Server.Items
{
[FlipableAttribute( 0x26C2, 0x26CC )]
public class ElvishBow BaseRanged
{
public SkillMod m_SkillMod0;
public SkillMod m_SkillMod1;

public override int EffectID{ get{ return 0xF42; } }
public override Type AmmoType{ get{ return typeof( Arrow ); } }
public override Item Ammo{ get{ return new Arrow(); } }

public override WeaponAbility PrimaryAbility{ get{ return WeaponAbility.ParalyzingBlow; } }
public override WeaponAbility SecondaryAbility{ get{ return WeaponAbility.MortalStrike; } }

public override int AosStrengthReq{ get{ return 30; } }
public override int AosMinDamage{ get{ return 16; } }
public override int AosMaxDamage{ get{ return 18; } }
public override int AosSpeed{ get{ return 25; } }
public override int OldStrengthReq{ get{ return 20; } }
public override int OldMinDamage{ get{ return 9; } }
public override int OldMaxDamage{ get{ return 41; } }
public override int OldSpeed{ get{ return 20; } }

public override int DefMaxRange{ get{ return 15; } }

public override WeaponAnimation DefAnimation{ get{ return WeaponAnimation.ShootBow; } }

[Constructable]
public ElvishBow() base( 0x26C2 )
{
Weight = 4.0;
Hue = 0x460;
Name = "Elvish Bow";
Layer = Layer.TwoHanded;
DurabilityLevel = WeaponDurabilityLevel.Indestructible;
AccuracyLevel = WeaponAccuracyLevel.Supremely;
Attributes.BonusDex = 10;
Attributes.WeaponSpeed = 10;
Attributes.WeaponDamage = 60;
DefineMods();
}

private void DefineMods()
{
m_SkillMod0 = new DefaultSkillMod( SkillName.Tactics, true, 10 );
m_SkillMod1 = new DefaultSkillMod( SkillName.Archery, true, 10 );
}

private void SetMods( Mobile m )
{
m.AddSkillMod( m_SkillMod0 );
m.AddSkillMod( m_SkillMod1 );
}

public override bool OnEquip( Mobile from )
{
SetMods( from );
return true;
}

public override void OnRemoved( object parent )
{
if ( parent is Mobile )
{
if ( m_SkillMod0 != null )
m_SkillMod0.Remove();
if ( m_SkillMod1 != null )
m_SkillMod1.Remove();
}
}

public ElvishBow( Serial serial ) base( serial )
{
DefineMods();

if ( Parent != null && this.Parent is Mobile )
SetMods( (Mobile)Parent );
}

public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}

public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}



Here is the message I recieve


Scripts Compiling C# scripts...failed (1 errors, 0 warnings)
- Error Scripts\Custom Scripts\ElvishBow.cs CS0116 (line 1, column 1) A name
space does not directly contain members such as fields or methods
Scripts One or more scripts failed to compile or no script files were found.


Any Ideas?
- Press return to exit, or R to try again.
 

gzero

Wanderer
Okay, now I know I need to define the class. I dont know how to do that, I thought I made it pretty clear I am new to this, I have followed all avenues I can to figure this out and learn. Perhaps you might SHOW me what you mean by 'define the class?'
 

Phantom

Knight
weird I could have sworn when I first looked at your script I didn't see your class declared.

You sure your class is in a .cs file? I assume you save the file?
 

Ali Baba

Wanderer
Im sorry to involve in your question, but i see this

[code:1]
private void DefineMods()
{
m_SkillMod0 = new DefaultSkillMod( SkillName.Tactics, true, 10 );
m_SkillMod1 = new DefaultSkillMod( SkillName.Archery, true, 10 );
}

private void SetMods( Mobile m )
{
m.AddSkillMod( m_SkillMod0 );
m.AddSkillMod( m_SkillMod1 );
}
[/code:1]
Can someone explain me what this does?
just learning, nothing more.
 

gzero

Wanderer
Yes, In the compiling results you can see that it is a .cs file. I had this question too and renamed the file with a .cs but then the compiler read it as .cs.cs, hehe, so I changed it back to a single .cs I'm stumped. As it compares with the simple Bow and RangedWeapon in the runuo files, I cannot see a problem. Is there a capitalization that should not be there? -but the same letters are capitolized in the working runuo script *sigh* -Any other ideas?
 

Phantom

Knight
Ali Baba said:
Im sorry to involve in your question, but i see this

[code:1]
private void DefineMods()
{
m_SkillMod0 = new DefaultSkillMod( SkillName.Tactics, true, 10 );
m_SkillMod1 = new DefaultSkillMod( SkillName.Archery, true, 10 );
}

private void SetMods( Mobile m )
{
m.AddSkillMod( m_SkillMod0 );
m.AddSkillMod( m_SkillMod1 );
}
[/code:1]

They are custom methods, that add SkillMods.
Can someone explain me what this does?
just learning, nothing more.
 

Ceday

Page
your code compiles just fine.
sometimes, there could be some unseen characters in the code.
I mean not only "white spaces" but also other characters.
And your error is in the first line, make sure there is not any in yours.
 

Ali Baba

Wanderer
Phantom said:
Ali Baba said:
Im sorry to involve in your question, but i see this

[code:1]
private void DefineMods()
{
m_SkillMod0 = new DefaultSkillMod( SkillName.Tactics, true, 10 );
m_SkillMod1 = new DefaultSkillMod( SkillName.Archery, true, 10 );
}

private void SetMods( Mobile m )
{
m.AddSkillMod( m_SkillMod0 );
m.AddSkillMod( m_SkillMod1 );
}
[/code:1]

They are custom methods, that add SkillMods.
Can someone explain me what this does?
just learning, nothing more.

??????
 

Ceday

Page
I guess it is a skill modifier class. (SkillMod)
when you equip the bow, it calls SetMods method which makes your some skills higher..(here, archer and tactics)

but I think he forgot to call "DefineMods" in the method of "SetMods"
 

Phantom

Knight
Ali Baba said:
Phantom said:
Ali Baba said:
Im sorry to involve in your question, but i see this

[code:1]
private void DefineMods()
{
m_SkillMod0 = new DefaultSkillMod( SkillName.Tactics, true, 10 );
m_SkillMod1 = new DefaultSkillMod( SkillName.Archery, true, 10 );
}

private void SetMods( Mobile m )
{
m.AddSkillMod( m_SkillMod0 );
m.AddSkillMod( m_SkillMod1 );
}
[/code:1]

They are custom methods, that add SkillMods.
Can someone explain me what this does?
just learning, nothing more.

??????

You asked what the did and I told you?
 

gzero

Wanderer
Well, I'm about to give up on this, I can see nothing wrong with it. You say it compiles for you all, but it wont for me ( Ghost in the Machine, I guess.
 

gzero

Wanderer
Well, I'm about to give up on this, I can see nothing wrong with it. You say it compiles for you all, but it wont for me ( Ghost in the Machine, I guess.
 

Hawkins

Sorceror
Re: A namespace does not directly contain members such as fi

Alatariel said:
Hello, I've a new private shard Im working on and beginning to learn to read C#. I have been able to compile Wolfs armor scripts, but anything else I have tried to compile (and thus far I only have tried simple weapons and such) gives me this same error: A namespace does not directly contain members such as fields or methods. (Line 1, comumn 1) I have tried tutorials, comparing with scripts that have worked, comparing with the scripts in runuo, and searching these forums like mad. I am not seeing any difference in the scripts introduction; nothing seems out of place to my untrained eye. Has anyone any ideas as to what the problem could be? Thank-you :?

Just curious, is it necessary to,

[code:1]using Server.Items[/code:1]
 

gzero

Wanderer
No, it is not neccesary, but it does not create an error also.

I have narrowed down the problem a bit but I still can't solve the problem -HELP! If I get a file thru a Zip, I do not get this message

- Error CS0116 (line 1, column 1) A namespace does not directly contain members such as fields or methods

but if it is a .cs I found here on the forums I get this message, even though the script looks fine, and there are no extra spaces. I have even tried putting in spaces to see if that would help -I'm up a creek unless I can solve this problem, and I have tried for days -Help!
 
Top