Page 1 of 1
"Else" trouble.
Posted: Tue Sep 22, 2009 11:35 am
by Havoc
I'm trying to get this function to work. Right now, if I have under 100 karma, it will return the message "You do not have enough Karma!", but the character graphic will still change. If I have above 100 karma, I will get the success message, and also, be turned into a Rat. I know this is probably something easy that I am just looking over, but I'm just a bit confused that the conditions being met/unmet changes the message but not the affect.
Any help is appreciated!
Code: Select all
function RatForm (character)
//
const karmarequired := 100;
var current_karma := CInt(GetKarma(character));
character.oldgraphic := character.trueobjtype;
character.graphic := 0xD7;
character.color := 0;
//
if (GetKarma(character)>=karmarequired);
PrintTextAbovePrivate(Character, "Your bones crunch as they bend and conform to the shape of a Rat.", Character);
SetObjProperty(character, "Graphic", cint(character.graphic));
SetObjProperty(character, "color", cint(character.color));
else
PrintTextAbovePrivate(Character, "Your Karma is not high enough!", character);
endif
endfunction
Re: "Else" trouble.
Posted: Tue Sep 22, 2009 12:33 pm
by *Edwards
Code: Select all
function RatForm (character)
//
const karmarequired := 100;
var current_karma := CInt( GetKarma( character ));
var oldgraphic := GetObjProperty( character, "Graphic" );
//
if ( current_karma>=karmarequired )
PrintTextAbovePrivate( Character, "Your bones crunch as they bend and conform to the shape of a Rat.", Character );
SetObjProperty( character, "Graphic", cint( character.graphic ));
SetObjProperty(character, "color", cint( character.color ));
character.graphic := 0xD7;
character.color := 0;
else
PrintTextAbovePrivate( Character, "Your Karma is not high enough!", character );
character.graphic := oldgraphic ;
endif
endfunction
Re: "Else" trouble.
Posted: Tue Sep 22, 2009 12:34 pm
by Damien.
You don't need the properties if they are of no further use too

Storing properties is bad!

Re: "Else" trouble.
Posted: Tue Sep 22, 2009 12:38 pm
by Havoc
@*Edwards
I had already attempted this.. for some reason, the initial character.graphic overrides anything after else. I still turn into a rat regardless of my karma.
Re: "Else" trouble.
Posted: Tue Sep 22, 2009 1:20 pm
by Yukiko
Assuming the original or
truegraphic is what is wanted here, try:
Code: Select all
else
PrintTextAbovePrivate( Character, "Your Karma is not high enough!", character );
character.graphic := truegraphic ;
endif
or
Code: Select all
else
PrintTextAbovePrivate( Character, "Your Karma is not high enough!", character );
character.graphic := CInt(GetObjProperty( character, "Graphic"));
endif
Re: "Else" trouble.
Posted: Tue Sep 22, 2009 1:48 pm
by Havoc
So, it turns out I was a bit of an idiot -- i wasn't using var before character.graphic, so instead of considering the argument it was just switching to the graphic!
Thanks Yukkiko, Damien, and *Edwards!
Code: Select all
function RatForm (character)
//
const karmarequired := 100;
var current_karma := CInt( GetKarma( character ));
var oldgraphic := GetObjProperty( character, "Graphic" );
var truegraphic := character.trueobjtype;
//
if ( current_karma>=karmarequired )
PrintTextAbovePrivate( Character, "Your bones crunch as they bend and conform to the shape of a Rat.", Character );
SetObjProperty( character, "Graphic", cint( character.graphic ));
SetObjProperty(character, "color", cint( character.color ));
character.graphic := 0xD7;
character.color := 0;
else
PrintTextAbovePrivate( Character, "Your Karma is not high enough!", character );
character.graphic := truegraphic ;
endif
endfunction
This works perfectly
