Scripts: 'else' doesn't work

Forum Archive - from http://theuniversal.net
Locked
User avatar
VDZ
Posts: 1205
Joined: Wed Apr 07, 2004 11:32 am
Location: Netherlands

Scripts: 'else' doesn't work

Post by VDZ »

Software:Unregistered Server
Version Number:0.51.3
________________________________________________________________________
Location
Virtua World
________________________________________________________________________
Description:
When using an if-else thing in a script, if the if condition is true, the script also executes the else part.
________________________________________________________________________
Steps to Replicate:

Code: Select all

//MMG settings
$kMMGBet = 100 //Amount of denari each player bets
$kMMGWin = 198 //Amount of denari the winning player receives

//The MMG script
Event( "&command", "InitMMG")
{
	$gMMGPlayer = 0
}

Event( "&command", "MMG")
{
	*msg %player% Welcome to Money Making game!
	*msg %player% The current bet is $kMMGBet
	*msg %player% To start, type &StartMMG.
}

Event( "&command", "StartMMG")
{
	if ($gMMGPlayer == 0)
	{
		$gMMGPlayer = %player%
		*msg %player% Waiting for another player.
		*say %player% is now playing the MMG.
		*say Type &StartMMG to join.
	}
	else
	{
		*say $gMMGPlayer
		*grantcash %player% -$kMMGBet
		*grantcash $gMMGPlayer -$kMMGBet
		$gMMGWinner = Rand(2)
		if ($gMMGWinner == 1) //Joining player wins
		{
			*say %player% wins $kMMGWin denari!
			*grantcash %player% $kMMGWin
		}
		else
		{
			*say $gMMGPlayer wins $kMMGWin denari!
			*grantcash $gMMGPlayer $kMMGWin
		}
		$gMMGPlayer = 0
	}
}
(No, the game does not work...you can't refer to players using variables.)
After doing &StartMMG, it checks if $gMMGPlayer is 0 or not.
If it is, it does $gMMGPlayer = %player% (resulting in 0 :( )
If it isn't (i.e. somebody has already started), it starts the game.
However, it also starts the game when $gMMGPlayer = 0. It shouldn't.
User avatar
VDZ
Posts: 1205
Joined: Wed Apr 07, 2004 11:32 am
Location: Netherlands

Post by VDZ »

It's also worth noting that second if-else, the one deciding the winner, works fine.
User avatar
Magicfinger
Staff
Staff
Posts: 1078
Joined: Tue Sep 30, 2003 10:38 am
Location: here,there and everywhere

Post by Magicfinger »

secondary to this....

it would be good to have a NOT operator morb's scripts seem to have quite a few...

Code: Select all

if something = something
{

}
else
{
   do something
}
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

i've had no problems with it in the blackjack script i have. that has ifs and elses out the arse. and nested upto 5(?) deep in the one i posted.

try closeing and reopening the server at all? and your client?

i noticed sometimes while making the blackjack script, it would do odd things one min, then a short while later, and without me changing anything, those oddities stopped by themselves. i even had one time where i started the game and it ran threw EVERY *msg command in the blackjack script, completely ignoring everything else in the script.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

oh, also, try changing the = = to just a single =?
Jere
Posts: 17
Joined: Wed Apr 11, 2007 7:05 pm
Location: Iowa

Post by Jere »

Magicfinger wrote:secondary to this....

it would be good to have a NOT operator morb's scripts seem to have quite a few...

Code: Select all

if something = something
{

}
else
{
   do something
}
shouldn't that be

Code: Select all

if something = something
{
   do something
)
else
{
   do something
}
?
User avatar
VDZ
Posts: 1205
Joined: Wed Apr 07, 2004 11:32 am
Location: Netherlands

Post by VDZ »

zaroba wrote:oh, also, try changing the = = to just a single =?
It was = by default, until I figured that might've been the cause, but it didn't fix it.
And I always restart my entire server to reload the script, so that can't be it either.

Jere; that's the point. Instead of saying 'if condition is not true, then do stuff', the script currently has to say 'if condition is true, then do nothing. Else, do stuff.'
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

well...theres really no point in that.
wouldn't a more logical solution would be to instead of 'if = do nothing, else = do something', you have 'if = do something, else do nothing' ?

mainly since the anything else could just be what ends the script.
User avatar
Magicfinger
Staff
Staff
Posts: 1078
Joined: Tue Sep 30, 2003 10:38 am
Location: here,there and everywhere

Post by Magicfinger »

its really about fulfilling multiple criterias...

so ...

Code: Select all


if ( var NOT = 1)
{
   do something
}

would trigger if var = any other number but one otherwise you would need to put conditionals in for every other number or create an else clause with do nothing in the if clause.
User avatar
Magicfinger
Staff
Staff
Posts: 1078
Joined: Tue Sep 30, 2003 10:38 am
Location: here,there and everywhere

Post by Magicfinger »

@vdz i can't get this to fail can you send me script if it is still an issue... at the usual email adress...

Not statements are in the next version... not sure when Mit Implemented that but all the code is there for it.
Locked