Looping a get input script?

XanMag
I'll post code if I need to but I hope this explanation is sufficient...

I have a computer in a room (check). It needs a password to continue operation and a negative result if an incorrect password is entered (check). Once the correct password is inputted another 'get input' runs asking the player which program they would like to run (check). The two programs are basically a hint system for the game. One program is titled "room information" and another is a "Dingo Database" (information on the bad guys in the game).

All is good so far using get inputs. My problem is this... I would like the player to be able to input a last name and get info, followed by a prompt like 'enter another name or type 'return'' to return to the main menu. I'm sure it has something to do with the loop script maybe? I'm sure I can make it work by adding the prompt followed by another 'getinput', but I have a feeling this might get a bit messy. Just looking for the easiest solution.

Does this make sense?

Let me know if I need to post my current code and I will.

Thanks in advance!

XanMag

lightwriter
I had a problem similar to this... you have to use a function and call the function again if he condition isn't met.

HegemonKhan
simply use a Function to add your scripts into (instead of a Verb), as this is exactly what Functions are for !!! (a Function is perfect as a loop block)

(though it can be difficult to get it to work if you make the design complex... especially as you can only have a single 'get input' and~or 'show menu' running at a time, for obvious reasons ~ I'm still... yes still, stuck on this very issue... laughs. It's been like 3 months... I wish I get this figured out in only 8 hrs... compared to 3 entire months and still no solution figured out, lol. So keep it as simple as you can, unlike me!)

for example:

<game name="xxx">
<start type="script">
name_function
</start>
</game>

<function name="name_function">
msg ("What is your name?")
get input {
name_variable = result
msg ("So, your name is " + name_variable + ".")
show menu ("Is this indeed your name?", split ("yes;no", ";"), false) {
if (result = "yes") {
player.alias = name_variable
msg ("Alright, {player.alias}, onto my next question...")
age_function
} else if (result = "no") {
msg ("Okay, then I'll ask you again...")
name_function
}
}
}
</function>

<function name="age_function">
// blah scripts
</function>


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

if you want to see some more complex usage:

(this uses the Parameters and maybe the return types ~ I'd have to re-check if I use the return types any where in my code or not ~ I can't remember)

viewtopic.php?f=18&t=4988

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

as for doing it in the GUI~Editor, via it's 'add a script' buttons:

create~add a Function, it's exactly like a Verb, just ignore the 'parameters add box' for now, you can leave it blank: don't add any parameters to it, and ignore the return type drop down box too for now: leave it as: [none]. Add in your scripts.

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

to do the looping of the Function (re-doing or doing again, the Function):

run as script -> add a~new script -> scripts -> 'call function' Script -> Name: 'whatever you want, example: name_function', Parameters: (don't add any)

or, in code, the code line for calling (looping ~ re-activating~using~doing~running the Function) a Function, is literally the 'name' of the Function, lol, for example:

name_function
age_function
race_function
race
age
class
class_function
classFunction
etc etc etc (whatever you decided to name each of your Functions as)

code is so much easier, lol. wink

---------

lastly, usually you have a Verb (or the Game Object's 'start' Script or a Command) for examples, and within the Verb (or the Game Object's 'start' Script or a Command), you add the 'call function' Script, to do the initial running of the Function (and then within the Function itself, you also have the same added 'call function' Script, to re-do or do-again, loop, the Function)

this above is maybe the critical thing to understand on how to set up or use a loop~Function.
(though, you can do more complex stuff, like having one looping Function 'calling on' another looping function too, so it can get really messy~complex, if you're a bad coder, don't know good structural~organizational code designs+methods~tricks, like I am ~ like me, lol)

XanMag
Thanks. I will tinker with it, but I have a feeling that I will be back!

HegemonKhan
try to keep your looping Functions and the design system as simple as you can, I know (but never learn) from experience, lol

to learn, try to make a simple looping function, and then try to expand, making more complex designs~systems.

-----

omg (oh my gosh), I totally forgot to...

BEWARE: creating functions that forever loop... (a never ending Function, will crash your quest, causing you to have to open back up quest, but you have to fix this issue as this is a no-no for a functional computer or a program~software, like quest, laughs)

a possible analogy would be for a calculator~computer~human trying to find the value of pi (it never ends and so you, the calculator, and~or the computer breaks down first), laughs ;)

pi is an EVIL NUMBER (in ancient times, pi literally was thought to be evil, an evil number, as were the other non-terminating non-repeating numbers).

XanMag
I'm back, but only to spread great news!! lol

I have finished the first of two programs on my in-game computer and did so without too many hiccups. And it is quite a complex system! Two hours later (and, more importantly, no headaches!!) and feeling pretty good about Xanadu 2. The second half of the computer tasks will be finished without a doubt tomorrow and I can finally move on to my last four rooms!

Thanks lightwriter and HK!

Happy Gaming!

HegemonKhan
excellent! :D
Though slow down, or you'll be surpassing me in no time, hehe :D (J/K, don't you dare slow down!, as that'd be awesome if you surpass me, as then I can pester you for help, oh will you regret it, muwhaha! lololol)

XanMag
Holy HELL!!! This is a lot of work! The second half of the computer program I'm trying to finish is the in-game hint system. I'm writing the hints at the ends of a room description that is built in to the program loop. I'm writing hints for each room in order of increasing "obviousness". I'm writing the hints in white on a white background, so the player has the option of highlighting the parts of the hint they want. I have 16 of my 27 rooms (with hints) completed (3 hours later! UGH!!).

There will be two hint systems in place. The partial hint system will include only those rooms that the player experiences prior to finding and using the computer and will be available at any time in the game with a 'hint' command, and the full hint system will be available after finding the computer and only while using the computer.

I know I am babbling, but do any of you see any problems doing it this way?

Thanks!

Thank God for my summers off!! lol

XanMag
Okay, so everything works. Well, not everything.

I have spent 30 minutes or so just testing my computer system loop function and I am very pleased with it, but there is this one tiny little problem that probably could go unfixed because it doesn't screw the game up. Nonetheless, here it is.

The first time the computer is used, I have the original script. It's set up this way to distinguish if the computer is hacked already or not so you don't have to keep putting the password in. So, that makes three get input codes in different places. One after entering the password (the IF) and one once the password has already been typed in (the ELSE). The third location of the program is the loop function. At the end of each of the possible player inputs (after the print msg script giving required info) in all three locations, I have a call function to loop the program so the player can simply type another name in. At the prompt where the player can enter a name or a place, it tells the player they can type in "stop" to stop using the computer all together. Here is the minor problem.

On occasion (never the first time through), the "stop" does not work although the scripts in each location have the exact same "stop" script. It might perhaps do the same thing with different names, but I have not seen that yet. Players will use the stop command multiple times whereas they will probably only look names/places up once.

You can foo-foo this if you want, because, like I said, it really doesn't mess anything up. It just leaves a minor smudge on an otherwise exemplary script! =)

If any of you have a possible solution or suggestion for me to look at, let me know. I don't really want to post the code here because it is a mighty mess to sort through to fix a minor issue. Just suggestions might lead me to a good place to look. I've searched through the script pretty thoroughly. I'll post code if any of you are REALLY, REALLY wanting to help. Thanks. =)

Happy Gaming!
XanMag

HegemonKhan
I'm still not exactly clear on your system setup, but of what I hope I correctly gathered from your post, here's some ideas:

<object name="computer">
<inherit name="switchable" />
// and all the other built-in stuff that is apart of this built-in feature, which I'm not that familiar with in code, lol. I don't know what the Verbs are for this 'turn on~off' built-in stuff, and etc.
<attr name="hacked" type="boolean">false</attr>
<attr name="password" type="string">xxx</attr>
<attr name="attempts" type="int">0</attr>
<logon type="script">
logon_function
</logon>
</object>

<function name="logon_function"><![CDATA[
if (computer.switchedon) {
if (not computer.hacked) {
if (computer.attempts <= 3) {
msg ("Password?")
get input {
if (ToString (result) = computer.password) {
computer.attempts = 0
computer_function
} else {
msg ("Wrong password, try again.")
computer.attempts = computer.attempts + 1
logon_function
}
}
} else if (computer.attempts > 3) {
msg ("Security protocol initiated: the computer is locked out, due to unauthorized attempted tries to input the password.")
// an idea to deal with this, is using a (secret well hidden) Object (in your game), that will upon use, will either make the computer be 'hacked' or it will put the 'attempts' back to 0.
}
} else if (computer.hacked) {
computer_function
}
} else if (not computer.switchedon) {
msg ("You need to turn on the computer to use it, silly.")
}
]]></function>

<function name="computer_function">
msg ("Type in a command to the terminal~command line.")
get input {
// blah scripting (your info scripting, the actual use of your computer, the commands about~for 'names~people' and 'places' that you talk about in your post)
}
stop_function
</function>

<function name="stop_function">
show menu ("Do you want to stop?", split ("no;yes",";"), false) {
if (result = "yes") {
computer.switchedon = false
} else if (result = "no") {
computer_function
}
}
</function>


instead of using 'stop', I'm just using the built-in 'switchedon' Boolean Attribute (make your computer be 'switchable' Type): there's no 'stop', but there is: on vs off (when you want to stop using the computer, you turn off the computer, and when you want to start using the computer, you turn it on), lol.

Also, you'll need a way of 'hacking' the computer, I don't know how you want to do this, so you'll need to implment this (some method, which will set: computer.hacked = true, else the 'logon_function' will always ask for your password, instead of skipping it).

hopefully this gives you the ideas you need to fix it up yourself.

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

Support

Forums