Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 09-06-2005, 02:10 AM   #1 (permalink)
Master of the Internet
 
Radwen's Avatar
 
Join Date: Apr 2005
Location: Nowhere
Age: 22
Posts: 11,653
Default Using vars in other scripts.

How do I create a var in order that I can use it in etheir a different script or same script but different method ?

Let's say I have this script :
Code:
using System;
using Server.Items;
using Server.Mobiles;
using Server.Targeting;
using Server.SkillHandlers;

namespace Server.Scripts.Commands
{
	public class Enseigner
	{

		public static void Initialize()
		{
			Server.Commands.Register( "Enseigner", AccessLevel.Player, new CommandEventHandler( Enseigner_OnCommand ) );
		}

		[Usage( "Enseigner [skill]" )]
		[Description( "Permet à un maitre d'enseigner un skill." )]
		public static void Enseigner_OnCommand( CommandEventArgs e )
		{
			string skill = e.ArgString;
			string cibleur = e.Mobile.Name;

			switch (skill)
			{
				case "Swords" :
				{
						e.Mobile.SendMessage( "A qui voulez-vous enseigner le combat à l'épée?" );
						e.Mobile.Target = new Enseigner.InternalTarget();
						string skillname = "le combat à l'épée";
					break;
				}
				case "Tactic" :
				{
						e.Mobile.SendMessage( "A qui voulez-vous enseigner la tactique de combat?" );
						e.Mobile.Target = new Enseigner.InternalTarget();
						string skillname = "la tactique au combat";
					break;
				}
				default :
				{
						e.Mobile.SendMessage( "Votre entrée n'est pas un skill." );
					break;
				}	
			}	
		}

		private class InternalTarget : Target
		{
			public InternalTarget() :  base ( 8, false, TargetFlags.None )
			{
			}
			protected override void OnTarget ( Mobile from, object targeted )
			{
				int cible = from.Serial;

				//from.SendMessage( "{0} vous enseigne {1}", cibleur , skillname );
			}
		}
	}
}
The string cibleur and skillname are needed in the protected override void method for my sendmessage fonction.
How would "import" in a way the value of those variables ?
Is there parametres to set like in PHPscript ?
Would a global var be a better choice ? If so how would I do so ?

The reason why the questions are so broadranged is that this is bugging me in a few of my scripts. So by answering this question your actually helping me with 4 scripts .

Thanks for reader and even more for answering
Radwen is offline   Reply With Quote
Old 09-06-2005, 02:39 AM   #2 (permalink)
Master of the Internet
 
TMSTKSBK's Avatar
 
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
Default

you would need to pass it as an argument. so...saying you wanted to access dummyFunction():

public void dummyFunction( string blah )
{
*does stuff*
}


to call dummyFunction, you'd say:

dummyFunction( x ); //where x is a string

while you're at it, check this out:
erm.....
__________________
Goodbye, folks.
TMSTKSBK is offline   Reply With Quote
Old 09-06-2005, 10:07 AM   #3 (permalink)
Master of the Internet
 
Radwen's Avatar
 
Join Date: Apr 2005
Location: Nowhere
Age: 22
Posts: 11,653
Default

Ok, so it would be preferable to set it in a function and then call in the function..

Because I tried :

protected override void OnTarget ( Mobile from, object targeted, string skillname )

But it gave me a compile error (before posting this I mean).
Is this because it is not a legal argument set for this method ?
Radwen is offline   Reply With Quote
Old 09-06-2005, 10:55 AM   #4 (permalink)
Master of the Internet
 
TMSTKSBK's Avatar
 
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
Default

well if that explodes, make it a public or private variable, and reference it from wherever you are. if you make it private, you have to be in the same class to see it.

for instance:

public string yarr;

public void elmethod1()
{
dostuff...
yarr = result;
elmethod2();
}

public void elmethod2()
{
string internal = yarr;
domorestuff...
}
__________________
Goodbye, folks.
TMSTKSBK is offline   Reply With Quote
Old 09-06-2005, 02:57 PM   #5 (permalink)
Master of the Internet
 
Radwen's Avatar
 
Join Date: Apr 2005
Location: Nowhere
Age: 22
Posts: 11,653
Default

Great, thanks a lot.
Radwen is offline   Reply With Quote
Old 09-06-2005, 02:59 PM   #6 (permalink)
Master of the Internet
 
TMSTKSBK's Avatar
 
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
Default

You're welcome /me is glad to help...as long as people try to do it themselves
__________________
Goodbye, folks.
TMSTKSBK is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5