Help with simple problem.

Rat
29 Nov 2015, 07:55
I'm trying to design a game so that once the player "eats" sleeping pills they are able to sleep in their bed.

I am planning to simply have two messages appear- one to appear if the player has "eaten" the pills and one to appear if they haven't.

How would I manage this?

Sorry- I feel like this is incredibly simple but I'm a total noob and need help.

Thank you.

XanMag
29 Nov 2015, 08:22
Here is a snippet from my tutorial game. I'll polish it up later, but hopefully this will help. You should be able to copy-paste this into a game of yours and see how it works. Actually, I'd open a new game and go to code view. Paste the code after /game and before /asl in code view.

  <object name="edible flag room">
<inherit name="editor_room" />
<alias>edible triggering an event room</alias>
<description><![CDATA[In this room, you will see how to eat something which causes an event to occur. Do these steps to see it in action:<br/>1. go to sleep<br/>2. eat the muffin<br/>3. go to sleep<br/>4. wake up]]></description>
<object name="bed">
<inherit name="editor_object" />
<look>It's a bed.</look>
<lie type="script">
if (GetBoolean(muffin, "eaten")) {
msg ("That muffin really did you in! You lie down in bed and quickly fall asleep. (type 'wake up' to wake back up).")
}
else {
msg ("You lie down in bed and toss and turn. You just aren't tired enough to fall asleep.")
}
</lie>
</object>
<object name="muffin">
<inherit name="editor_object" />
<look>It's a muffin made of flour, sugar, eggs, milk, valium, and vanilla.</look>
<eat type="script">
msg ("You scarf down the valium laced muffin. Tasty.")
RemoveObject (muffin)
SetObjectFlagOn (muffin, "eaten")
</eat>
</object>
<object name="Magoo">
<inherit name="editor_object" />
<inherit name="editor_player" />
<inherit name="namedmale" />
<attr name="pov_look">You're Magoo. A simple being trapped in a test game.</attr>
<look type="script">
if (game.pov = Xanadu) {
msg ("Holy moly! That looks exactly like you! To take control of Magoo, just type 'switch to Magoo'.")
}
else {
msg ("You are a simple being trapped in a test game.")
}
</look>
</object>
<command name="wake up cmd">
<pattern>wake up</pattern>
<script>
msg ("You wake from sleep after a long nap feeling refreshed. You get out of bed.")
MoveObjectHere (muffin)
</script>
</command>
<command name="go to sleep cmd">
<pattern>go to sleep</pattern>
<script>
if (GetBoolean(muffin, "eaten")) {
msg ("That muffin really did you in! You lie down in bed and quickly fall asleep.")
}
else {
msg ("You lie down in bed and toss and turn. You just aren't tired enough to fall asleep.")
}
</script>
</command>
</object>


I would suggest NOT using the edibles option under the features tab of the object. Just create the verb 'eat' under the verb tab, add eat, and run the scripts you want to run. The built-in edibles options never really worked well for me.

After you 'go to sleep' in this tutorial, it gets a bit sloppy, but it's 3:20am here and I'm tired. If you have questions or need clarification, please ask and I'll respond after I wake up! Good luck!

XanMag

HegemonKhan
29 Nov 2015, 09:22
for the concept of what you're doing (as XanMag's sample-demo game already covers what you need), take a look at this thread:

(it's on something entirely different, but the concept is a very fundamental one to programming and game making: 'if' logic)

viewtopic.php?f=10&t=5622

it takes time to train your brain in this 'if'-logic, but you've got no choice as that's how you make games through computers. And there's no real shortcuts either, just be patient, and slowly you'll learn more and more, as your train your brain to think in this way.

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

don't worry about it, even some of the "simpliest" stuff isn't simple for new people, we all had the same difficulty when we first jumped into trying to code or make a game (unless you're a born programming~code genius, but for us normal people, it's a very long and slow process to learn to program and~or to learn how to make a game, let alone actually making a game, sighs)