Friday, February 27, 2015

rotating descriptions (alternate method)

A question to me got me thinking about object property arrays, and it occurred to me that'd be another reasonable way to handle rotation descriptions.  The main perk of this method is that you wouldn't have to replace the routines if you have more than 5 descriptions to work with.  The big question to Hugo coders is whether:
long_desc
Rotate
rotate_desc "It's a door." "It's still a door." "Stop looking at it." \
"I mean it." "I really do."
Is as acceptable as:
long_desc
{
rotate( "It's a door.", "It's still a door.", "Stop looking at it.", \
"I mean it.", "I really do.")
}

Anyhow, here is the entire code if anyone wants to see it!

property rotations ! objects with rotating descriptions need a property to hold
! a value
attribute recycle ! give this attribute to cycle back to the beginning when end
! is reached
property rotate_desc ! holds descriptions to rotate
property random_desc alias rotate_desc
routine Rotate(obj)
{
if not obj
obj = object
local n
obj.rotations += 1
n = obj.rotations
print obj.rotate_desc #n
if n = obj.#rotate_desc
{
if obj is recycle
obj.rotations = 0
else
obj.rotations -= 1
}
}
!\ I sometimes like random descriptions, too, so I threw in a random description
version \!
routine RandomDesc(obj)
{
local x,n
if not obj
obj = object
x = obj.#random_desc
do
n = random(x)
while (n = object.rotations)
object.rotations = n
print obj.random_desc #n
}
door red_door "red door"
{
noun "door"
adjective "red"
article "the"
rotations 0
long_desc
Rotate
rotate_desc "It's a door." "It's still a door." "Stop looking at it." \
"I mean it." "I really do."
between startlocation east_room
!is recycle ! uncomment if you want descs to cycle
}
object rock "rock"
{
article "a"
noun "rock"
in STARTLOCATION
long_desc
RandomDesc
random_desc "A rock." "2nd rock desc." "3rd rock." "4th rock."
rotations 0
}
view raw rotate2 hosted with ❤ by GitHub

Thursday, February 26, 2015

object description rotation

This suggestion was made to me:
Another thing that would be handy would be some kind of list manager like in TADS or Inform that would make it easier to make things that change descriptions every time you look at them. For example:

long_desc
{
    rotate( "It's a door.", "It's still a door.", "Stop looking at it." )
}
Now, traditionally, you would do such a thing with code like this:

object box "box"
{
article "a"
noun "box"
in startlocation
misc 0
is openable container
long_desc
{
if self.misc < 3 ! no reason to increase it indefinitely
self.misc += 1
select self.misc
case 1: "First desc."
case 2: "Second desc."
case 3: "Third desc."
}
}

But, of course, sure, some helper routines could be written for anyone who wants the functionality of the suggestion above.  Following is some example code for doing such a thing.  I guess I could add it to Roodylib if enough people think it'd be useful.

property rotations ! objects with rotating descriptions need a property to hold
! a value
attribute recycle ! give this attribute to cycle back to the beginning when end
! is reached
!\ My Rotate routine can handle up to five descriptions. Of course, it could
be expanded to do more. Unfortunately, there's no cool way to get the routine
to just adapt to whatever arguments you throw it so it basically has to check
every expected argument by hand.\!
routine Rotate(arg1, arg2, arg3,arg4,arg5)
{
local n
object.rotations += 1
n = object.rotations
select n
case 1: print arg1 ! we'll assume this routine won't be used with one
! "rotation" so we don't need to check for arg2
case 2
{
print arg2
if not arg3 ! if there are only 2 descriptions
{
if object is recycle ! should it cycle?
object.rotations = 0 ! start back at the beginning
else
object.rotations -= 1 ! or just subtract one so it stays the
! same next time
return
}
}
case 3
{
print arg3
if not arg4
{
if object is recycle
object.rotations = 0
else
object.rotations -= 1
return
}
}
case 4
{
print arg4
if not arg5
{
if object is recycle
object.rotations = 0
else
object.rotations -= 1
return
}
}
case 5
{
print arg5
if object is recycle
object.rotations = 0
else
object.rotations -= 1
return
}
}
!\ I sometimes like random descriptions, too, so I threw in a random description
version \!
routine RandomDesc(arg1, arg2, arg3,arg4,arg5)
{
local x,n
if arg1: x++
if arg2: x++
if arg3: x++
if arg4: x++
if arg5: x++
do
n = random(x)
while (n = object.rotations)
object.rotations = n
select n
case 1:print arg1
case 2: print arg2
case 3: print arg3
case 4: print arg4
case 5: print arg5
}
view raw Rotate hosted with ❤ by GitHub

And examples of objects that use these would look like:

door red_door "red door"
{
noun "door"
adjective "red"
article "the"
rotations 0
long_desc
{
rotate( "It's a door.", "It's still a door.", "Stop looking at it.", \
"I mean it.", "I really do.")
}
between startlocation east_room
!is recycle ! uncomment if you want descs to cycle
}
object rock "rock"
{
article "a"
noun "rock"
in STARTLOCATION
long_desc
{
RandomDesc("A rock.","2nd rock desc.", "3rd rock.","4th rock.")
}
rotations 0
}
view raw rotate examples hosted with ❤ by GitHub

So, yeah, let me know if you guys want it in Roodylib or what.

Sunday, February 8, 2015

Scene Managing

Lately, I was looking at the code for a game that used constants and a global variable to keep track of scene changes, something I've done in at least one of my WIPs, too. It got me thinking that it'd be nice to have some code available for spitting scene stuff out so authors don't have to reinvent the wheel each time.

A room might check scene settings like this:

enumerate start = 1 step * 2
{
START, JOURNEY, EXPLODED_DYNAMITE, END
}
room start_room "Start Room"
{
long_desc
{
if Seen(EXPLODED_DYNAMITE)
"This place is in shambles now that you exploded all that dynamite!"
else
"Wow, this place is pristine."
}
}


And here is the actual scene routines and code:

! example linear game scenes
!enumerate start = 1
!{
! FIRST_SCENE, SECOND_SCENE, THIRD_SCENE, FINALE
!}
! example unordered scene game (must also #set UNORDERED_SCENES)
!enumerate start = 1 step * 2
!{
! START, PATH1, PATH2, PATH3, PATH4, END
!}
#set SCENE_MANAGER
#set UNORDERED_SCENES
#ifset SCENE_MANAGER
#ifset UNORDERED_SCENES
global current_scene
#endif
global scene
routine Seen(obj) ! returns true if the given scene has been "seen" yet
{
#ifset UNORDERED_SCENES
if (scene & obj)
return true
#else
if scene => obj
return true
#endif
}
routine CurrentScene ! returns the value of current_scene or the scene variables
{
#ifset UNORDERED_SCENES
return current_scene
#else
return scene
#endif
}
routine SetScene(obj) ! changes the scene (or current_scene if using UNORDERED_SCENES) variable to obj
{
#ifset UNORDERED_SCENES
current_scene = obj
scene = scene | obj
#else
scene = obj
#endif
}
#endif ! ifset SCENE_MANAGER


Anyhow, not sure how useful this will be to most people so I probably won't add it to Roodylib, but there it is!