|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Master of the Internet
Join Date: Apr 2005
Location: Nowhere
Age: 22
Posts: 11,653
|
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 );
}
}
}
}
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 ![]() |
|
|
|
|
|
#2 (permalink) |
|
Master of the Internet
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
|
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. |
|
|
|
|
|
#3 (permalink) |
|
Master of the Internet
Join Date: Apr 2005
Location: Nowhere
Age: 22
Posts: 11,653
|
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 ? |
|
|
|
|
|
#4 (permalink) |
|
Master of the Internet
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
|
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|