Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Trading Program - DBPro

Author
Message
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 12th Dec 2008 22:45
Hello all! I'm still a but id a newcomer when it comes to DBPro

Ive been trying, for a few weeks, to program a simple trading system, one similar to the ones you see in most RPGs nowadays. Ive got nowhere so far...

What I am trying to do is create a system where I buy something from the sellers inventory for a specific amount of currency, then have it added to my inventory.

I intend to develop this further, but for now, I want to start with this.

As far as I know, i need to be using lots of variables.

Cheers all!

DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 12th Dec 2008 23:21
I think your getting a little ahead of yourself. Correct me if I'm wrong but I think you need to take a few steps back.

You need to understand the following (as in like the back of your hand):
+ Variables

+ Arrays.
Both Typed and Multidimensional.
Getting data into an array as well as out.

+ Data types.
What's the difference between and real and an integer, when to use either and why? Converting data from strings for example.


Once you know these things building a simple inventory system shouldn't be too much off a problem. You need a Typed array to store all you Items.


Assuming your array is called

Item(MaxItems)

Your Type might look something like this:



So for example "A Woolly Hat" would look like the following


You can then reference the Item using the ItemID in your code. And set the value of "Item(0).ItemOwned" to 1 when you buy it from a NPC.

You can then have a subroutine to check the array from Items with ItemOwned as 1+ and update your Players menu.
Need more Items then increase the ItemOwned Value.

You may want a .MaxItem field so for example you can only buy 5 mega elixirs at once.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 14th Dec 2008 12:09
Ok, I now know about variables, which i actually quite easy
I'm still a bit rusty on arrays, although I do understand its concept. The tutorial by Sixty Squares is good, but marginally confusing, to say the least!

I sort of understand your example, though I'm failing to understand how I would implement that into code.

To be honest, I have no idea how/where to even begin!

baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 14th Dec 2008 18:50
Here's what Ive got so far.




Now i dont really know how to proceed...

Cheers all for any help

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 15th Dec 2008 01:23 Edited at: 15th Dec 2008 01:43
Until someone who understands it better comes a long to help I'll at least let you know some stuff I saw.
-I think its good practice to put your functions at the very end underneath all your code.
-You don't need the 1 inside the parameters to your functions since you don't need to send any information to the function.
-You actually need to put the typed array stuff into an array...
You need to declare an array for your items. Then put the information into the array for Item 1, Item 2, and so on. You also need to to declare you own type like the example DsarchyUK gave for "MyItems".

So lets say you would have a max of 20 items in your whole game. You would declare an array

Or 19 if your going to start at 0 like DsarchyUK example. But, the code you have starts at 1.
Then you would add information in to the Items array with the second example DsarchyUK gave.

I used 1 as the starting position in the array to go along with what you had.

Again I don't have a very good understanding of this so don't take what I say as set in stone. Maybe you can work on what I said until someone comes and and can help and explain better.

I was therefore I can be.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 15th Dec 2008 01:36
Ok, i'll take a proper look at that later, when I get some more time. Its 00.30 in the UK now, and im in need of my beauty sleep

Cheers Phantom

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 15th Dec 2008 01:40 Edited at: 15th Dec 2008 02:36
Alrighty then Good night!

And here's an example code I wrote so you can see what I mean visually.


Here's my question though. Obviously not aimed at you but anyone else that can help. What would be the best method to have the Item ID name description and such for all the items he wants. Would you you just keep going with

and so on and keep adding that to the code and just make a huge list. Or can you put it into a different file or something. I tried using another .dba or .txt file to have the item list but it didn't work. Seems to me if you could put it into a different file it would make it easier to edit any item you wish.

I was therefore I can be.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 15th Dec 2008 12:03
Well, the beauty sleep went well!

Thanks for the code, its really helpful.
Just a few questions on how to implement that kind of idea into my code.
-For some reason, ive started getting an error message (Attached)
-Is this the correct kinda thing to be going along with ?


-Correct me if I'm wrong, but Phantom's idea with the .txt file storage sounds good. It seems organised, which is what Im looking for right now, so everything doesn't become a mess!

Cheers all

Attachments

Login to view attachments
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 15th Dec 2008 14:37 Edited at: 15th Dec 2008 15:59
Your ideas are on the right track. It won't be long before you have it down. Here is some code that should be helpful, my suggestions are within.

EDIT: I commented out some of the code that I didn't have the media for.


Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 15th Dec 2008 17:03 Edited at: 15th Dec 2008 17:04
wow Pillarofire I never thought of doing the adding through a function that makes it so much easier and cleaner. and arrays are indeed global if you declare them outside of the function

I was therefore I can be.
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 15th Dec 2008 22:40
You can delete individual items from arrays by using ARRAY DELETE ELEMENT. You should write a function that will add the same item to the Inventory, and delete it from the Shop.

Just use the ItemID, parse the array with a FOR LOOP, and when you find the element with the ItemID that you want to trade, store that element and exit the FOR LOOP. Then use that element that you stored to retrieve the information for that item, Use the addItem() for the parameters for Inventory, and then remove it from the Shop.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 15th Dec 2008 23:43
With the code snippet you just gave, what I get is the two items, printed on the screen. I'm assuming that this is what is meant to happen, and that is it, or am I missing something.

I do apologise for the snail-like pace, its just that I'm struggling to keep up with you professionals!

Cheers lads

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 16th Dec 2008 03:13
Yeah its just printing to screen what is in the shop. It's meant as an example to show you how a trade system would work and how to put the items in an array so you can manipulate it when needed. You should change the code or implement it how you want into your code.

I was therefore I can be.
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 16th Dec 2008 03:49
Yes, baconboy2, you and Phantom 2590 have got it. It was meant as an example to inspire you to think on your own. Don't worry about being "snail-like" I was there once too. That's why I'm here to help.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 16th Dec 2008 19:54
Right, so how would I go about implementing what you've just said into a workable program?

Here's what I have at the moment, though I'm kinda confused how I would now go about expanding it. To be honest, this is the absolute limit of my knowledge. I'm more of a 3d, rpg programmer, albeit with little knowledge of that either!



Cheers

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 16th Dec 2008 22:47
What kind of game are you trying to create. Or do you just want a merchant simulation type of thing.

I was therefore I can be.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 16th Dec 2008 23:50
At the moment, I want to try and create a merchant simulation 'type of thing'.
I guess I could put it into a game, but the sole purpose is eductional/simulation.

I'm actually an AS Level Economics student (For you Americans, AS Level is a grade year in the British eduction system, similar to High School in the US I believe) I intend to apply my economical knowledge whilst creating this system/simulation.

In the future, when I have grasped more of an understanding of this, I hope that it can be implemented into other people's games, as a sort of template for an advanced economic system, say for use in online games, virtual worlds and so on.
Thats my dream, so to speak.

Phantom 2590
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Earth...
Posted: 17th Dec 2008 00:00 Edited at: 17th Dec 2008 00:06
You need to declare the type in your program. You can't just set the array as the type without declaring it first.
Something like this.

And why don't you use the function Pillarofire had for adding items to the shop. Instead of typing all those out for every item.

What's the texture you keep loading into your code?

I was therefore I can be.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 17th Dec 2008 11:08
The texture, which I have now decided to remove, was just a background for the program. It was nicked from another game, and was the inventory window.
There were some resizing issues, as it was absolutley huge!

baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 17th Dec 2008 11:09
Sorry for the double post, btw.


Ive just been adding a few things to the code so far, and I want to add an image for each item in the shop. This is what I've done.
(You may need images for the crowbar and the bread btw)



Cheers lads

Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 17th Dec 2008 12:22
I see you started on a function to Load each of the images for the items.

It is always a good idea to have the help files handy. Check the syntax for a FOR NEXT statement.
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 17th Dec 2008 13:26
Well, the bit I'm worried about is that fact that when I try to run the program, an error appears for

Saying that the command could not be understood. Is that related to the load image function, by any chance?

Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 17th Dec 2008 13:57
Possibly, are you compiling the code you posted before? Can you copy the entire code you're trying to compile so I can determine that?
baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 17th Dec 2008 14:10


Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 17th Dec 2008 14:18 Edited at: 17th Dec 2008 14:27


This is causing the error.

Change it to this:


The incomplete function is the problem.

EDIT:
First, You get another problem, the LOAD IMAGE command needs two parameters.

Second, you really don't want to load an image every cycle of the loop. You only need to load it once, if you want to draw it, you use PASTE IMAGE. This brings up the point that you should store the ImageID in your Item Type, so that when you want to paste it you can pass the PASTE IMAGE command the ImageID.
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 17th Dec 2008 15:16
Here it is all fixed up with some extras.


baconboy2
17
Years of Service
User Offline
Joined: 30th Jul 2007
Location: Liverpool, UK
Posted: 17th Dec 2008 15:54
Wow, that seems pretty complicated, cheers!

Having looked at the code, I see that if there is no image present, then a small white box will appear. Thats all fine and dandy, but when there is an image present, its bloody huge!
How do I resize the images into the little tile area?

Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 18th Dec 2008 01:00
Well first of all, it would be a good design consideration to use only images of all the same dimensions. Second that the dimensions are something moderate; I usually use 32, or 64. And third, that the images are squares. If you really can't do that however, there are other alternatives. Unfortunately there are no native commands (that I know of) for resizing 'Images' directly, so you would have to paste the image to a bitmap, resize the bitmap and then grab the image. Or, and I favor this option, you can use sprites.

A sprite is a rectangular 3D plane, textured with an image, and placed so that the plane is perpendicular to the camera at all times. (actually locked to the screen) So instead of dealing with 3D coordinates, you use 2D to place a sprite.

The method for using a sprite is this:

1. Load an image for the sprite: LOAD IMAGE FileName$, ImageNumber
2. Make a sprite from the image: SPRITE SpriteNumber, Xpos, Ypos, ImageNumber

This is simple, the image will be loaded, and displayed on the screen with the upper-left corner at Xpos, Ypos in screen coordinates(y increases as you go down the screen).

Now that there is a sprite, resizing is no longer a chore as there is a nifty command: SIZE SPRITE SpriteNumber, XSize, YSize

If we want our sprite to be 64px X 64px, then we use 64 for XSize and YSize, obviously.

See if you can write the code to make the program use sprites instead of images. Remember: at any time you have a question, first use the F1 key (help), if you still can't figure it out don't be afraid to ask me.

Cheers.

Login to post a reply

Server time is: 2024-11-25 14:51:10
Your offset time is: 2024-11-25 14:51:10