If Then Statements not working properly?

lyteside
27 Jun 2013, 21:59
I've been away for a while, but interested in using the new technology to create a game. I immediately encountered a problem with the if/then statements. I attached a pic for reference. There are three objects I'm using.

Broom, Bed, Player

When I do a standard if/else statement (checks for broom property, then checks for everything else), it works great.

But once I add the complexity of if else [if/else], it doesn't work great. The finally instruction doesn't work (it checks for the player, but it doesn't print my final message if the player condition isn't met). Any suggestions?
Screen Shot 2013-06-27 at 2.50.02 PM.png

Pertex
28 Jun 2013, 06:16
You are using this pattern: <pattern>search for #object#</pattern>
So if you search for an object that is not reachable for the player it prints the unresolved message. You should change it to
<pattern>search for #text#</pattern>
In the script do something like

object= GetObject(text)
if (object=null){
msg("There is no " + text +" here"))
} else {
if (object.alias = "broom") {
...

lyteside
28 Jun 2013, 23:34
awesome! How would you tweak the code so that the player can type any alias of the object. Currently, that code only works if the player puts in the exact name of an object. :(

HegemonKhan
29 Jun 2013, 06:10
Pertex' Code (I was helped too with this same thing, though it was~is for my combat system coding, hehe):

(just replace the stuff as needed to match what you're doing in your game~coding)

enemy = GetObject (text)
if (enemy = null) {
foreach (obj,AllObjects()) {
if (obj.alias=text) {
enemy = obj
} else {
msg ("There seemingly is no " + text + "here.")
}
}
}
// the rest~continuation of the code, being able to use ' enemy ' now for it


as the ' GetObject (text) ' searches for the NAME while if you use an ALIAS, which is what is seen by the game player~user and not the NAME, then you'll end up with quest not finding the object, ' enemy=null ' , as the game player~user types in the ALIAS. To get around this, Pertex sets up a way to search all objects in the game, ' if (enemy=null) { foreach (obj,AllObjects()) { ' , looking to see if those objects' ALIASES match the ALIAS that the game player~user typed in, ' if (obj.alias=text) ' , and if there's a match, then that variable name~label for the GetObject (text) is set to~as that searched object who's aliases matches the ALIAS that was typed in by the game player~user, ' enemy=obj ' . If there's no match, then there's a message saying it, ' msg ("There seemingly is no " + text + "here.") ' . Also, the~this code is ready to be continued for that match and now set up variable name~label with what ever coding you want, ' // the rest~continuation of the code, being able to use ' enemy ' now for it ' .

-------

here's an example of the first part of my combat system, so you can see how you can then continue the code using that variable name~label (in my case, it is ' enemy '):

<command name="fight_command">
<pattern>fight #text#</pattern>
<script>
fight_function (game.pov,text)
</script>
</command>

<function name="fight_function" parameters="self,text">
enemy=GetObject(text)
if (enemy=null) {
foreach (obj,AllObjects()) {
if (obj.alias=text) {
enemy=obj
} else {
msg ("There seemingly is no " + text + " here.")
}
}
} else if (not check_reachable_function (enemy) = true) {
msg ("There seemingly is no " + enemy.alias + " here.")
} else if (not DoesInherit (enemy,"character_object_type")) {
msg (enemy.alias + "is seemingly not something that you can battle.")
} else if (GetBoolean (enemy,"hostile") = false) {
msg (enemy.alias + " is seemingly not something that you can battle.")
} else if (GetBoolean (enemy,"dead") = true) {
msg (enemy.alias + " is already dead.")
} else {
battle_sequence_function (self,enemy)
}
</function>


You could put your script into the COMMAND's script, I chose to put the script into a separate function, which is " called upon " (activated) by the COMMAND's script (in code, it's simple the name of the function (and its parameters), ' fight_function (game.pov,text) '. In the GUI~Editor, it is the: Add a~new script -> Scripts -> Call function