Making commands work anywhere

OurJud
I've just developed a method for hacking into a device (see other thread) and although I eventually got it working, I've hit upon a little snag.

It uses a password system, which throws the player back and forth between two rooms each time the player enters an incorrect password.

In essence I have four rooms: lounge, wrongpassword, login, log out

'lounge' - this is where the player and the ePad start. In this room I created the following, separate command scripts:

'1234' (correct password >> moves player to 'login' room - this room will act as the ePad itself)
'#text#' (incorrect password/any input >> moves player to 'wrongpassword')
'use address book' (calls the address book image)
'log off' (clears the screen and returns the player to the lounge - this is set as a hyperlink using {command:Log off})

I then had to add these same four commands to the 'wrongpassword' room, so that the game would recognise them when the player is moved there.

The little snag I've hit upon, is having to have these sets of commands in both rooms, so that they will be understood when the player is thrown from room to room. Meaning that if I want to give the player the option to use the laptop regardless of where he is, I'll need to add the commands to every single room in my game.

I know the problem is triggered because I 'move' the player when they enter a wrong password, but it's the only way I could make it work the way I wanted.

How do I ensure the commands I've listed above will be understood, regardless of where the payer is?

HK mentions something about using verbs in the other thread, but they're not verbs.

OurJud
I need to use the input/result= command on the ePad, to look for the correct password. I can do this, but how do I 'return' the player to the enter password sequence if they input the incorrect one?

If I just say: If input = "1234" >> move player to login room. Else print "Incorrect password" a second attempt to enter the password gets "I don;t understand that command" as the game has dropped out of the ePad use by this point.

This would be solved by having the player type 'use epad' each time, but this isn't how a password sequence works.

jaynabonne
Regarding your first question, put your global commands in the Commands section under "game". Then they will be available everywhere.

For the second, I know you have gone with the mutli-room design, but there are other approaches. The basic idea is to have a piece of script that you can invoke again from the wrong password case. One way to do that is to put the script into a function so it can re-invoke itself. For example, let's say that you have a command named EpadCommand with pattern "use epad". It can be set up like this:

  <command name="EpadCommand">
<pattern>use epad</pattern>
<script>
msg ("Enter password")
get input {
if (result="1234") {
MoveObject (player, login)
}
else {
msg ("Incorrect password")
do(EpadCommand, "script")
}
}
</script>
</command>

The idea behind this is that if the player enters the wrong password, it tells them so and then simply invokes the same command script again. You can accomplish the same thing by moving the script into a function and having the function invoke itself (and have the command invoke the function).

OurJud
Thanks much. The 'Try again' was a compromise if I'm honest, so this is great.

I knew exactly what I needed to do (throw the player back to password input if they enter the wrong one) but I just didn't know how to do it... doubly frustrating :x

I haven't tested this yet, but will it allow the player to still use other commands such as 'use address' book to call the address book image up?

OurJud
Tried that code, Jay, and I get the error:

Failed to load game.
The following errors occurred:
Error: Error adding script attribute 'script' to element 'EpadCommand': Invalid variable name ''


I'm not sure I did it right. I added a command to the global commands list. In the first box I put 'use epad' and in the second one I put EpadCommand.

I then clicked the code box on the script and added your script.

jaynabonne
Would you be able to post the code view look at that command? It might be easy to spot the problem.

OurJud
jaynabonne wrote:Would you be able to post the code view look at that command? It might be easy to spot the problem.

The code view look?

Sorry, you must think me so damn stupid, but what do you mean? I used the exact same code you posted above. Or do you mean a screen grab of the UI?

Oh, I think I know what you mean. You mean because the code adapts itself when you flick back to it?

It's exactly the same, save for the first line.

<command___SPACE___name = "EpadCommand">
<pattern>use epad</pattern>
<script>
msg ("Enter password")
get input {
if (result="1234") {
MoveObject (player, login)
}
else {
msg ("Incorrect password")
do (EpadCommand, "script")
}
}

jaynabonne
That's it. :) I've never seen that __SPACE__ thing before. So I'm suspicious of that. Also, you didn't post the close tags for the script and command (</script> and </command>), so I'm not sure if those are there properly. If you could get rid of that so that it's just "<command name=..." and make sure there are correct closing tags, that might fix it. You might have to fix the close tag as well, if it got messed up somehow. It should be just </command>.

Marzipan
I know you guys all like your code, but how would I set up something like this using the GUI? I assume I need to pick If/expression/function...but it's the exact syntax of the 'get input' and 'results' part that's tripping me up.

OurJud
jaynabonne wrote:That's it. :) I've never seen that __SPACE__ thing before. So I'm suspicious of that. Also, you didn't post the close tags for the script and command (</script> and </command>), so I'm not sure if those are there properly. If you could get rid of that so that it's just "<command name=..." and make sure there are correct closing tags, that might fix it. You might have to fix the close tag as well, if it got messed up somehow. It should be just </command>.

Nope, it's not having it, Jay. I thought I'd found the problem when I went back to your code, as I was indeed missing the closing tags (the code doesn't quite fit in the window, and I didn't notice there was more below the window).

Anyway, I tried again and got the error:

Failed to load game.
The following errors occurred:
Error: Error adding script attribute 'script' to element 'EpadCommand': Invalid variable name ''



When I switched back to code view, it had put that _SPACE_ thing back in, so I changed it back to <command name="EpadCommand"> , but I still get the error.

jaynabonne
What you can do to set it up via the GUI is to create the command with the GUI and maybe put a dummy "print message" command in the script to give the script a body. Then in code view, replace the script body with the one in my script. (I tend to do stuff like that myself.)

As far as what you have, I know you probably don't want to post your game file, but that should make it really easy to fix if you could get it to me somehow (either here or email). The error message is pointing to something strange. It might be something amiss downstream of the command. Even if you had misspelled "EpadCommand" in the "do" part, it should still load. I can't even munge my file to make it give that error (so far), so I don't know how to diagnose it.

One other thought: search the entire file for EpadCommand and make sure something with that text hasn't crept in elsewhere.

OurJud
jaynabonne wrote:What you can do to set it up via the GUI is to create the command with the GUI and maybe put a dummy "print message" command in the script to give the script a body. Then in code view, replace the script body with the one in my script. (I tend to do stuff like that myself.)

As far as what you have, I know you probably don't want to post your game file, but that should make it really easy to fix if you could get it to me somehow (either here or email). The error message is pointing to something strange. It might be something amiss downstream of the command. Even if you had misspelled "EpadCommand" in the "do" part, it should still load. I can't even munge my file to make it give that error (so far), so I don't know how to diagnose it.

One other thought: search the entire file for EpadCommand and make sure something with that text hasn't crept in elsewhere.

Thanks, Jay. I'll have a look later, but I need to sleep now. What I will do, if I may, is send you my entire game code by PM?

OurJud
jaynabonne wrote:What you can do to set it up via the GUI is to create the command with the GUI and maybe put a dummy "print message" command in the script to give the script a body. Then in code view, replace the script body with the one in my script. (I tend to do stuff like that myself.)

As far as what you have, I know you probably don't want to post your game file, but that should make it really easy to fix if you could get it to me somehow (either here or email). The error message is pointing to something strange. It might be something amiss downstream of the command. Even if you had misspelled "EpadCommand" in the "do" part, it should still load. I can't even munge my file to make it give that error (so far), so I don't know how to diagnose it.

One other thought: search the entire file for EpadCommand and make sure something with that text hasn't crept in elsewhere.

Thanks, Jay. I'll have a look later, but I need to sleep now. What I will do, if I may, is send you my entire game code by PM?

Won't fit in a PM, so I'll just post it here for everyone to steal :?

jaynabonne
I don't see the "do" version of EpadCommand in your game. Is this the latest file?

You can also send me the file via email. (jaynabonne at gmail dot com)

Marzipan
jaynabonne wrote:What you can do to set it up via the GUI is to create the command with the GUI and maybe put a dummy "print message" command in the script to give the script a body. Then in code view, replace the script body with the one in my script. (I tend to do stuff like that myself.)


I meant more for this kind of situation in general, where you want the game to take and remember the player's input. I prefer to stay away from code because I'm hopeless at it myself, and I don't want the answer to 'can I do this?' to always have to boil down to 'only if someone else posted code doing that exact, specific thing that I can then copy and paste'. With the GUI it's just a simple step by step process that's easy to memorize and can be applied to a billion different situations.

But I'm sure I can figure out a way to fudge it all with commands, and I probably shouldn't be hijacking OurJud's thread anyway, so no worries if there's not a simple answer. :)

jaynabonne
Here's what the script looks like in the editor.

Screenshot 2014-12-13 19.13.40.png

Marzipan
Hurray! :D

I knew it was just something simple I was doing wrong. I kept choosing the 'function' option after 'expression' and thought I had to do something specific with get input there.

jaynabonne
I never would have known that was it without looking. It's not really obvious that "do" translates to "Run object". :) (or vice versa)

HegemonKhan
@Jay:

wow, never realized that I can call~loop the Command directly, laughs (though using Functions is still really useful, as the scripting is likely to be needed elsewhere too besides just the Command).

--------------

@Marz:

the 2 SUPER Scripts that let you do 90% of everything that you want to do in your game:

1. the 'set a variable or attribute' Script:

game states~data

VARIABLES:
-> Variables: local
-> Attributes: global

run as script -> add new~a script -> variables -> 'set a variable or attribute' Script -> [EXPRESSION]: but this requires some simple code writing, OR choose [whatever] you need (I don't understand all the GUI~Editor's choices, so I just use the [EXPRESSION] choice) -> (see below for the simple code writing, if you chose to use the [EXPRESSION] choice)

Variables (local: temporary states only for that scripting that it is in):

examples:

variable_name_string = Value_or_Expression

examples:

result = Value_or_Expression

notice how there's no 'attachment' to an Object, thus it is not 'globally saved', and thus not 'globally loadable'.

msg ("What is your gender?")
get input {
-> // you type in: male
-> // hidden, done automatically by the quest engine: result = "male"
-> player.gender_string = result
-> // player.gender_string = "male"
-> msg ("You are a " + player.gender_string + ".")
-> // Output: You are a male.
}

show menu ("What is your gender?", split ("male;female", ";"), false) {
-> // you choose: female
-> // hidden, done automatically by the quest engine: result = "female"
-> player.gender_string = result
-> // player.gender_string = "female"
-> msg ("You are a " + player.gender_string + ".")
-> // Output: You are a female.
}

handled = (true or false)
value = Value_or_Expression
you_go_first = (true or false)
y = x + 5
1 = Value_or_Expression
A = Value_or_Expression
etc etc etc

Attributes (global game states, so long as the Object exists):

Object_name.Attribute_name = Value_or_Expression

notice how Attributes are 'attached' (see the period~dot?) to Objects? By attaching Attributes to Objects, they're 'globally saved' (so long as the Object exists), which means that they're 'globally loadable' too. This is the same thing as 'adding' (attaching) Attributes to Objects in the GUI~Editor:

'xxx' (Object) -> Attributes (Tab) -> Attributes -> Add ->

(Object name: xxx)
Attribute Name: xxx
Attribute Type: (String, Integer~int, Double~Float~Floating Point, Boolean~Flag, Lists, Dictionaries, Objects, etc)
Attribute Value: (depends upon the Attribute Type)

examples:

=Values:

player.strength = 100
HK.strength = 100
Marz.strength = 100
orc.dead = false
player.eye_color = "blue"
player.damage = 830.12

=Expressions:

HK.favorite_colors = split ("black;red", ";")

HK.physical_damage = HK.weapon.damage + HK.weapon.damage * HK.strength / 100 - orc.armor.defense - orc.armor.defense * orc.endurance / 100

2. the 'if' Script:

actions~events

run as script -> add new~a script -> scripts -> 'if' Script -> [EXPRESSION]: I prefer but you got to write in the code, or [whatever] choice -> (see below if you're using the [EXPRESSION] choice)

(recognize this below?)
Object_name.Attribute_name = Value_or_Expression

in code, it *conceptually* looks like this:

if (Object_name.Attribute_name = Value_or_Expression) {
-> script(s)1
} else if (Object_name.Attribute_name = Value_or_Expression) {
-> script(s)2
} else if (Object_name.Attribute_name = Value_or_Expression) {
-> script(s)3
// etc more 'else ifs' as needed (or less as needed)
} else {
-> script(s)4
}

---------------------

jaynabonne wrote:I never would have known that was it without looking. It's not really obvious that "do" translates to "Run object". :) (or vice versa)


that's my problem with helping via the GUI~Editor, the conversions between how stuff is done~labeled in the GUI~Editor, vs in-code, is very ambigious and disconnected... (and it's a pain having to switch back and forth between GUI~Editor mode and Code View mode everytime to figure out what is the conversion-connections)

(code is so much better, hehe ~ I prefer writing in code to the GUI~Editor anyways. Though, I still got a boatload more code to learn, sighs)

OurJud
jaynabonne wrote:Here's what the script looks like in the editor.

Screenshot 2014-12-13 19.13.40.png

Thanks, Jay. that's far easier for me to follow to, as it's the UI.

Fantastic! Works wonderfully :)

Thank you.

OurJud
Ah! Wait!

There is a problem with this, Jay. There's no way out of the loop.

On the messages that follow inputs I added {command:log off:Log off} as a way out, but clicking that is taken as a password attempt and just runs the loop.

OurJud
Phew! Found a way out of the loop!
epad_use_GUI.jpg

jaynabonne
Very good! I'm glad it's working for you. :)

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums