Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RPG help
#1
I didn't know quite how to create a subject for this topic that would state what I wanted it to... but here is the question:

What would be the easiest way to have on the overworld (world) map a treasure chest that the player can only open once? I know that I could say something like openedchest = 1 or something but is there an easier way?

Also, is there someway to make it so that the program knows if someone has done something already? I.E.> gone to the magical door and realized that it needs a key and so then the key appears.

Thanks for any help that you could give.

-Nova
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#2
Easier than having a flag variable? I fear not. It is as easy as possible: you just have OpenedChest = 0 at the beginning, and when you open it just set OpenedChest = -1 (in QB, 0 is FALSE and -1 is TRUE). Then you can make further comprobations:

Code:
IF OpenedChest THEN
   <blah>
ENDIF

This is called "flag variable". When you have many things that need a flag, you can just make an array for flags, and remember which flag was assigned to which events.

Imagine that there are three events in your game: Talk to the giant, rob the treasure, and kiss the mademoiselle. You can write down in some sheet of paper this data:

Quote:Talk to the giant = 0
Rob The Treasure = 1
Kiss The Mademoiselle = 2

Then you have your flags array in your game

Code:
DIM Flags%(2)

When you talk to the giant, you just set the flag #0:

Code:
... Flags%(0) = -1   ' Talk to the giant

And the same for robbing the treasure; when the player robs the treasure you just:

Code:
... Flags%(1) = -1
.

Imagine that the mademoiselle only wants to kiss you if you robbed the treasure and talked to the giant, so...

Code:
...
IF Flags%(0) AND Flags%(1) THEN
   ... Here the mademoiselle kisses you
   Flags%(2) = -1  ' Kiss the Mademoiselle
   ...
ENDIF

All you need is understand how those flags work. Please feel free to ask if you didn't understand something Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
Thanks a lot Na_th_an, this really helps. So does this mean that I could have an array such as chests(n) where n is the number of chests throughout the game... and then to have it be opened do you just set chest(n) to -1?


then say something like


Code:
if Chests(1) = -1 then
harloadput "boxopen.put", myarray() 'pp256 sprite image.
put (20,20),myarray, pset
end if

if x = 10 and y = 10 then
if chests(1) = -1 then print "The chest is already open"
if chests(1) = 0 then print "You got a potion!"
end if

would that work? Thanks for all the advice, by the way, over the sumthin 4 - 5 months or whatever I have been asking.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#4
Yeah, you understood it quite well Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
Thanks for all your help, you have truly been an asset to my now growing knowledge of QB.

*bows*

YOU ARE THE QB GURU (I don't care what anybody else says)
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#6
Hey another question:


can you use the variable() thing for strings?

such as...


dim item(10) as string


and have it work in the same way? Thanks for any help.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#7
It depends on what do you want to use it for. For flags, using integers is faster, mainly 'cause strings comparisons are much slower than integer comparisons.

It can be fine to store anothre data, such as the item names. In fact, it will be easier to code an engine if everything is correctly stored in arrays.

It would be even better to have a structure (TYPE) to store things, for example:

Code:
TYPE ItemType
   name AS STRING *10
   x AS INTEGER
   y AS INTEGER
   flag AS INTEGER
END TYPE

DIM Items(20) AS ItemType

Now you have an array to store info for 20 items. For example, if the item #4 is a bow located at (20, 10) in the map you just give values to the array position #4:

Code:
Items(4).name = "Bow"
Items(4).x = 20
Items(4).y = 10
Items(4).flag = 0

That will make things easy, for example when detecting if the player
takes a new item:

Code:
FOR i%=0 TO 10    ' Number of items
   IF player.x = Items(i%).x AND player.y = Items(i%).y THEN
      IF NOT Items(i%).flag THEN   ' If item has not been taken
         PRINT "You found the "; Item$(i%).name;"."
         Item$(i%).Flag = -1
      END IF
   END IF
NEXT i%

You know, having things correctly stored in memory just makes your coding easier. For example, in a text adventure you could code the text for each location and its exits one by one, but it would be easier having a data structure containing all the descriptions and exits and having a generic location which reads the data and acts properly.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)