Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

An array of objects?

 [1/4] from: vache::bluejellybean::com at: 21-Dec-2000 16:55


For a text-based game (a MUD, essentially), I'm trying to create a system by which the players can travel from room to room within the world, via. an array of rooms (i.e. Room(1,1), Room(200,2) etc.). I thought this would be an easy task but I have had trouble. How do you create arrays of objects in Rebol? I originally tried creating a block of objects, so I could access them like world/1/description, but it errors (and it isn't in an array, which would makes things harder down the road) --- world: make block! [ room1: make object! [ directions: [0 1 0 1] ; N S E W description: "You are in a dark cave!" ] room2: make object! [ directions: [1 0 0 1] description: "You are outside!" ] ]

 [2/4] from: mike:yaunish:home at: 21-Dec-2000 18:16


At 04:55 PM 21/12/00 -0800, you wrote: You may want to make the rooms into blocks instead - of course there are a hundred ways to skin this cat - but here's what I know. room1: [ directions [0 1 0 1] ; N S E W description "You are in a dark cave!" ] room2: [ directions [1 0 0 1] description "You are outside!" ] rooms: [] append/only rooms room1 append/only rooms room2
>> rooms/1
== [ directions [0 1 0 1] description "You are in a dark cave!" ]
>> rooms/2/description
== "You are outside!" Good luck, if you go this way it will bring up all the fun ways to create paths.
>For a text-based game (a MUD, essentially), I'm trying to create a system >by which the players can travel from room to room within the world, via.
<<quoted lines omitted: 21>>
>[rebol-request--rebol--com] with "unsubscribe" in the >subject, without the quotes.
Mike Yaunish [mike--yaunish--home--com]

 [3/4] from: rebol:techscribe at: 21-Dec-2000 18:27


Vache, the reason you are having problems is because of the set-word notation you are using and the fact that you are not reducing your block. Here's what I mean: 1. reducing the block: block: [ make object! [ directions: [0 1 0 1] description: "You are in a dark cave." ] ]  What do you have here? You do not have a block consisting of an object! You have a block consisting of the words make object! and an embedded block consisting of the words directions and description, the block [0 1 0 1] and the string "You are in a dark cave.". The length of block is 3, namely the word make, the word object! and the block containing the values you intend for the object:
>> length? block
== 3 Also try
>> first block
== make
>> second block
== object!
>> third block
== [ directions: [0 1 0 1] description: "You are in a dark cave." ] Compare to: block: reduce [ make object! [ directions: [0 1 0 1] description: "You are in a dark cave." ] ] REBOL will first reduce the block, which means that it evaluates the contents of the block. The reduce function returns a block that contains the evaluated contents of the block it was passed. The word block now references a block that indeed contains an object as you intended.
>> length? block
== 1
>> type? first block
== object! 2. The set-word problem. Now, let's assume you were to use the following code (Note that I added reduce to your first first line): REBOL [] world: make block! reduce [ room1: make object! [ directions: [0 1 0 1] ; N S E W description: "You are in a dark cave!" ] room2: make object! [ directions: [1 0 0 1] description: "You are outside!" ] ] What you now have are two global words called room1 and room2. The block referenced by world now looks like this:
>> print mold world
[ make object! [ directions: [0 1 0 1] description: "You are in a dark cave." ] make object! [ directions [1 0 0 1] description: "You are outside." ] ] What's changed? The two set-words room1 and room2 are no longer contained in the block. You can now access the block as world/1/directions world/1/description world/2/directions world/2/description Hope this helps, Elan Vache wrote:

 [4/4] from: al:bri:xtra at: 22-Dec-2000 21:31


Vache wrote:
> room1: make object! [ > directions: [0 1 0 1] ; N S E W
<<quoted lines omitted: 4>>
> description: "You are outside!" > ]
If you're going to have a lot of rooms, then use a dialect to store them. For example: [S W] "Dark cave" "You are in a dark cave!" [N W] "Outside" "You are outside!" Which is: block! string! string! exits short desc long desc and then use the code that was published earlier to create objects from blocks that look like tables. I hope that helps. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted