Logic for climbing a tree

loreamuno
01 Nov 2015, 05:01
Okay, so, I'm banging my head here trying to figure out how to program the following (would really love some help):
There's a room, it's the beach.
On the beach there's an object, it's a palm tree. The palm tree has a verb associated to it, which is climb. The palm tree has another object inside which is called 'top of the palm tree'. At the top of the palm tree, there's are four coconuts. I want to make it so that player tries three unsuccessful attempts to climb it before they're able to go to 'top of the palm tree' and are able to be in reach of the coconuts and grab them.

I'm a relative newbie to this program, I just am having difficulty wrapping my head around this. Any tips?

Thanks!

HegemonKhan
01 Nov 2015, 05:31
conceptually (as code, but you should get the design from it, I hope... lol):

the key concept is having an Integer Attribute, which increases upon each click on the 'palm_tree' Object's 'climb' Verb, and then an 'if' Script to check for that 'counting~adding~increasing' Integer Attribute's Value, for what to do, based upon it.

regardless of whether you just use the GUI~Editor, or you do coding, you're going to have to develop this 'if logic' way of thinking with your brain, as this is how a computer is able to make a game, and thus is required for you to make a game. It takes a while to train your brain in this thought-process as it's not normal (we do it naturally-instinctively-subconsciously-internally without ever realizing it). While not quite the same, it's close enough: you have to constantly be thinking "should I do this or should I do this?", as somewhat like the 'if-logic' that you need to learn to use for making a game.

player.coconut_quantity = 0

palm_tree.coconut_quantity = 4
palm_tree.climb_attempt = 0

// -----------------------------------------------------------------------------------

// your 'palm_tree' Object's 'climb' Verb:

if (palm_tree.climb_attempt < 3) {
palm_tree.climb_attempt = palm_tree.climb_attempt + 1

// you try to climb, and fail
// palm_tree.climb_attempt = palm_tree.climb_attempt + 1
// palm_tree.climb_attempt = 1
//
// you try to climb again, and fail
// palm_tree.climb_attempt = palm_tree.climb_attempt + 1
// palm_tree.climb_attempt = 2
//
// you try to climb for a third time, and fail
// palm_tree.climb_attempt = palm_tree.climb_attempt + 1
// palm_tree.climb_attempt = 3

} else if (palm_tree.climb_attempt = 3) {

// you try to climb for a fourth time, and... SUCCEED!

if (palm_tree.coconut_quantity > 0) {
player.coconut_quantity = player.coconut_quantity + palm_tree.coconut_quantity
palm_tree.coconut_quantity = 0
msg ("You take the " + palm_tree.coconut_quantity + "coconuts", now you won't die of thirst for a little while longer...)
} else {
msg ("You climbed the palm_tree, even though there's no coconuts, and now you got rashes, blisters, and torn skin on your hands, arms, feet, legs, and groin, but hey, at least you got a nice view of the beach, sand, and the ocean, water... (what an idiot!)")
}
}


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

learn to use these 2 SUPER SCRIPTS, and especially when used together, you can do 90% of everything that you want to do in your game:

1. run as script -> add new script -> variables -> 'set a variable or attribute' Script

2. run as script -> add new script -> scripts -> 'if' Script

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

I know this post doesn't help you too much, but see if you can figure it out (using the GUI~Editor's 'if' and 'set a variable or attribute' Scripts), and if you can't, let me know, and I'll help you more specifically~thoroughly~step-by-step~etc through it.

if~when XanMag has the time, he~she will help you much more directly~better in doing what you want through the user-friendly GUI~Editor (making a sample game for you to test~play~study), unlike my scary and un-helpful code posts, laughs.

or, whoever else, we're a small but very helpful community. Though, a lot of us are busy with real life (school or work or whatever) so we're a bit less available as often as in the summer, obviously.

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

here's a link for a guide on using Attributes, but it may scare you even more (be even more daunting than this post of mine):

viewtopic.php?f=18&t=5559

and here's this link too, hopefully it'll help you understand scripting designs (mostly if logic, but also includes looping and etc) better too:

viewtopic.php?f=10&t=5570

and if you don't already know about these useful links:

http://docs.textadventures.co.uk/quest/
http://docs.textadventures.co.uk/quest/tutorial/
http://docs.textadventures.co.uk/quest/guides/
viewforum.php?f=18 (more guides: libraries and code samples)
http://docs.textadventures.co.uk/quest/ ... ation.html (RPG character creation)

enjoy :D

XanMag
01 Nov 2015, 13:09
Here is a simple way to cheat the code heavy stuff for climbing a tree after multiple attempts. I would, however, try to learn HK's way because that type of code will definitely come in handy the more game you make later. But, for now, if that is a bit much for you, try the "cheater's way".

Here is the code for my climb a tree room. If you copy-paste this into a new game you can see it within the GUI editor and manipulate it as you want (just go to code view in the GUI (looks like a note card - 2nd button from the right at the top) and paste the code below just above the last line (/asl). Forgive me if the copy-paste doesn't work - too lazy to test it, but I think it's good to go. Below the code is a brief explanation as to what I did.

  <object name="climbing a tree room">
<inherit name="editor_room" />
<description>You are on the beach. You can see a palm tree.</description>
<object name="palm tree">
<inherit name="editor_object" />
<look>It's a pretty run of the mill palm tree. It looks like it might be climbable.</look>
<takemsg>You cannot take a palm tree. It is firmly rooted into the ground and you are NOT Hercules.</takemsg>
<climb type="script">
msg ("You put your little monkey feet on the base of the tree and your little monkey hands around it around the trunk. You try to shimmy up the tree put you only make it a few feet before sliding back down.")
RemoveObject (palm tree)
MakeObjectVisible (palm tree1)
</climb>
</object>
<object name="palm tree1">
<inherit name="editor_object" />
<look>It's a pretty run of the mill palm tree. Even though you failed the first time, it looks like it might be climbable.</look>
<takemsg>You cannot take a palm tree. It is firmly rooted into the ground and you are NOT Hercules.</takemsg>
<visible type="boolean">false</visible>
<alias>palm tree</alias>
<climb type="script">
msg ("You clamp your little feet firmly to the tree base and grab a hold of the trunk with your scrawny hands. You jump, cling, jump, cling, jump, cling... You make it about half way to the top of the tree before you lose your grip and fall into the sand below.")
RemoveObject (palm tree1)
MakeObjectVisible (palm tree2)
</climb>
</object>
<object name="palm tree2">
<inherit name="editor_object" />
<look>It's a pretty run of the mill palm tree. It looks like it might be climbable if you are brave enough to try again.</look>
<takemsg>You cannot take a palm tree. It is firmly rooted into the ground and you are NOT Hercules.</takemsg>
<visible type="boolean">false</visible>
<alias>palm tree</alias>
<climb type="script"><![CDATA[
firsttime {
msg ("You wrap your feet around the base of the palm tree and clasp your hands around it like you are trying to choke it. You focus and climb slowly. Your thin muscles tremble, but slowly, inch by inch, you climb the tree. Just as you are about to lose your grip, you manage to make your way to a comfortable perch atop the tree.<br/>")
wait {
MoveObject (Magoo, top of palm tree)
}
}
otherwise {
msg ("With as much difficulty as the your last attempt, you climb back up the palm tree.")
MoveObject (Magoo, top of palm tree)
}
]]></climb>
</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>
</object>
<object name="top of palm tree">
<inherit name="editor_room" />
<description>You are at the top of a medium sized palm tree. The only way back down is, well... down.</description>
<exit alias="down" to="climbing a tree room">
<inherit name="downdirection" />
<runscript />
<script type="script">
msg ("You begin to climb down the tree. You slip and fall gracelessly to the soft beach below.")
MoveObject (Magoo, climbing a tree room)
</script>
</exit>
<object name="coconut">
<inherit name="editor_object" />
<look>It's a coconut roughly the size of a coconut.</look>
<take />
<takemsg>Nice. You now have one large, fuzzy, brown nut.</takemsg>
</object>
</object>


1. I made one palm tree and placed it in my "beach" room.
2. I then copy-pasted this 'palm tree' object two more times, but this time I unticked the 'visible' box on the Setup tab to make it invisible within the room. Also, make sure you put the name 'palm tree' in the alias box or else you will see the trees with a number after them in your game!
3. Add a climb verb for the 'palm tree' object. For the climb verb for 'palm tree' I added a script that printed a message (essentially 'you failed climbing the tree'.) I also added a 'remove object' script that removed the palm tree from the game AND a script to 'make object visible' (palm tree1).
4. For the climb verb for palm tree1, I did the same thing. I changed the message to avoid monotony, but I also removed palm tree1 and made visible palm tree2.
5. For palm tree2's climb verb, I made a successful climb attempt and added a script to 'move object to room' script where I moved my player to a room called 'top of palm tree'. FYI, I put the successful climb script in a 'first time' script and in the 'otherwise' part of that script I simply moved the player to 'top of palm tree'.
6. At the top of the palm tree "room" I made a one way exit down to the beach (make sure you do not make it a two way exit because then it will defeat the purpose of your climb verb!).

In short, I made three palm trees, two of which were invisible. I added a climb verb for the palm tree in which I printed a message saying 'you fail', a remove object palm tree script, and make visible script for palm tree1. I repeated that with palm tree1. For the climb verb for palm tree2, I moved the player to a room called top of palm tree.

Hope this helps! Good luck!

XanMag

EDIT: Just thought of this... and it might be easier (less objects but you need to know flags).
1. Add a palm tree.
2. Add verb climb and put in an 'If' script.
3. For the 'If' part of the 'If' script, add 'If object palm tree has flag name experience', then add a successful climb to a room called top of palm tree.
4. In the 'Else' part of that 'If' script, add a 'first time' script.
5. In the first time part of that script, add a print message like "You made it 1/3 of the way up."
6. In the 'Otherwise' part of that script, add a print message like "You made it 2/3 of the way up." Also in the 'Otherwise' part of this script, add a 'Set object flag' script. Add the flag name 'experience' to the palm tree.

Voila! Now when you try a third time to climb the palm tree, it will be successful! I'll post code here if it is helpful.

There is a 3rd way I can think to skin this cat, but it is flag heavy. I think either of these options are quite doable for you. If you have trouble, let me know. Good luck!

loreamuno
02 Nov 2015, 02:57
HegemonKhan wrote:
the key concept is having an Integer Attribute, which increases upon each click on the 'palm_tree' Object's 'climb' Verb, and then an 'if' Script to check for that 'counting~adding~increasing' Integer Attribute's Value, for what to do, based upon it.

regardless of whether you just use the GUI~Editor, or you do coding, you're going to have to develop this 'if logic' way of thinking with your brain, as this is how a computer is able to make a game, and thus is required for you to make a game. It takes a while to train your brain in this thought-process as it's not normal (we do it naturally-instinctively-subconsciously-internally without ever realizing it). While not quite the same, it's close enough: you have to constantly be thinking "should I do this or should I do this?", as somewhat like the 'if-logic' that you need to learn to use for making a game.



I sincerely appreciate all the help and advice!

I know I'm a little behind in terms with coding and C language, and I'm going to check all of the links that you sent me!

I ended up using XanMag's last explanation and it worked! :D
Soooo friggin happy!

I will get this in due time, but thanks again for all of the helpful guidance!

loreamuno
02 Nov 2015, 02:58
XanMag wrote:
EDIT: Just thought of this... and it might be easier (less objects but you need to know flags).
1. Add a palm tree.
2. Add verb climb and put in an 'If' script.
3. For the 'If' part of the 'If' script, add 'If object palm tree has flag name experience', then add a successful climb to a room called top of palm tree.
4. In the 'Else' part of that 'If' script, add a 'first time' script.
5. In the first time part of that script, add a print message like "You made it 1/3 of the way up."
6. In the 'Otherwise' part of that script, add a print message like "You made it 2/3 of the way up." Also in the 'Otherwise' part of this script, add a 'Set object flag' script. Add the flag name 'experience' to the palm tree.

Voila! Now when you try a third time to climb the palm tree, it will be successful! I'll post code here if it is helpful.

There is a 3rd way I can think to skin this cat, but it is flag heavy. I think either of these options are quite doable for you. If you have trouble, let me know. Good luck!


This last guide toootally helped me out XanMag! Thanks for the 'cheat-sheet' and taking the time to help me out!
Wooo Hoooo! I've never been so stressed out over a palm tree in my life.