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!

Fatal error on random case

Fatal error on random case

Greetings. I'm trying to create an item that when double clicked gives you a check for a random amount and deletes the item itself. I have the other parts of the item working fine, but for some reason I keep getting a fatal error with this part. Btw, using 2.0RC1
Code:
	public override void OnDoubleClick( Mobile from ) 
	{ 
	if ( !IsChildOf( from.Backpack ) )
			{
				from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use 

it.
			} 
         else 
			switch ( Utility.Random(2))
			{
				default:
				case 0: from.AddToBackpack( new BankCheck( 100000 ) ); break;
				case 1: from.AddToBackpack( new BankCheck( 250000 ) ); break;
				
			}
			this.Delete;
	}
 

Alex21

Sorceror
I think it might be

Code:
default:

you havn't put a

Code:
break;

on it which would mean it was un-able to fall through.

but should works like this

Code:
default: break;

Any way be nice if you could post the error if that dosn't fix it.
 
the default is fine that way, i have many scripts that way - it is the same as doing "case 0: default:" etc

try this:

Code:
         else
		{ 
			switch ( Utility.Random(2))
			{
				default:
				case 0: from.AddToBackpack( new BankCheck( 100000 ) ); break;
				case 1: from.AddToBackpack( new BankCheck( 250000 ) ); break;
				
			}
			this.Delete;
		}
 

Alex21

Sorceror
Lord_Greywolf;734889 said:
the default is fine that way, i have many scripts that way - it is the same as doing "case 0: default:" etc

try this:

Code:
         else
		{ 
			switch ( Utility.Random(2))
			{
				default:
				case 0: from.AddToBackpack( new BankCheck( 100000 ) ); break;
				case 1: from.AddToBackpack( new BankCheck( 250000 ) ); break;
				
			}
			this.Delete;
		}

well. i didn't know the exact syntax that could be used. But what was the error he had?
 
no problem

but one of the things i learned about cases is you can do it like this:

case 0:
case 2:
case 6:
case 10: and what you put here will also be done by case 0, 2, 6 & 10; break
case 1:
case 3:
case 9:
etc
case 15: and will do 1, 3, 9, etc & 15; break
default: case 14: case 16: will do all that do not have it + 14 & 16; break

good to know for future reference

works with any variables that match up also

just remember that default means ANY that are not used anywhere else in it, so becareful on using it
 
Top