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.

DarkBASIC Discussion / bit of help with calulations

Author
Message
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 13:06
kay what i what is to have a menu with and inventory kay i can do that now the problem come well trying to fill the inventory. see i need some way of making it calulate where to put each item see
there are four space for inventory items
[_][_]
[_][_]
like so, now i need it to calulate whether or not a picture exists there or not so, if there where to items in the first two box
[F][F] F=full
[_][_]
then i need the computer to calulate that now i need to put one in the 3rd box. this is what i got now but it doesn't work



see and if you could shorten it that would be great. Plus at the moment it goes through all of this every loop if you could make it so when it goes in to the menu it works the calulates out so all it need to do in the loop is paste the right image (pasteing the right image need to be worked out before the loop but every time you go in to the loop)

thx
crystal
Newbie Now; Expert Later
Current project:The Sorus
http://us.f1.yahoofs.com/users/8e2ce249/bc/logo.jpg?bc6XVw.ALSzFxXyM[/img]
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 13:23 Edited at: 14th May 2003 13:24
Use a 2D array to symbolise which spaces are taken.

dim menu(2,2)

This will create the array which can be graphically shown as:



So if your first space is taken, menu(0,0)=1, if your 3rd one is taken menu(1,0)=1 etc. From there its easy.

Cheers,
Kentaree

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 13:50
kay i think i get it i'll
try
thx
crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 13:59
No problem

Cheers,
Kentaree

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 14:01
sorry doesn't work with that i get


i think its something to do with the order not the varibles themselves

crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 14:13
If you want to check in what order they're in, try something like.



This will check square (0,0) first, then (1,0), then (0,1), then (1,1). If it finds any space thats empty, it pastes the image, then breaks out of both for...next loops.

Whatever I did I didn't do it!
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 14:17
BTW, for using the paste image command in this example, I'd advise you use the x and y variables to calculate where to paste the image. For example, if the menu was at the top left of the screen (0,0) and each image was 150 pixels wideand 150 high, you could use something like:

paste image 1,x*150, y*150

to find the corresponding coordinates.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 14:29 Edited at: 14th May 2003 14:32
kay work fine except the code needs a command to make it so that if you do paste the image then it will input into the array that that space is now used

crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 14:41
Yep, stupid me

the completish code is



Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 14:42
let see. hold your breath hehe

Newbie Now; Expert Later
Current project:The Sorus
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 14:49
it works and i now what the problem it just how to fix it. the prob is it load them on the first loop but when it gets to the second the computer think the spots are filled so very soon you run out of spots. now the pictures in the spots will not change during the viewing of the menu so if i put that code at the top before the loop then all we need to do is instead on paste the image the we have to tell the computer that in the rest of the loop to padyte that picture there. now could we do this is a array so it would be something like



or something (sorry i'm new to arrays)
Crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 15:14
Hmm, I'm not sure if I totally understand you but if I do, you could set up an array as dim picture(amountOfPictures,2)

Where amountOfPictures is any amount you want, probably big if you have many pictures, and the 2 behind it hold the x and y values. For example, if you want the array to hold the x and y values of picture 10, you would use something like:

picture(9,0)=50
picture(9,1)=200

Arrays start at 0, so take one of the number you are using. We'll let the 0 value hold the x coordinate, and the 1 hold the y coordinate. Actually we could make it easier by declaring two variables as xCoordinate=0: yCoordinate=1 so we can actually use the array as
picture(9,xCoordinate)=50
Just for clarity.

To then paste them, you'd use another for...next loop

for i=1 to imageNo
paste image i, picture(i-1,xCoordinate), picture(i-1,yCoordinate)
next i

If this confuses you, just ask and I'll try to help you

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 15:26
yeah kinda confusing what i need is

the menu code starts here

kay now there i need to save the x and the y and the picture number so in the menu code it know what picture to put and where kay


kay is that that what i meant

crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 15:35
Right, try (not complete code, cut and paste it into your current prog):



Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 15:51
sorry image does not exist which bit do i have to change to fit my code and if it helps the pic will probally be 1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012 and 1013
i can make them small if it helps to
37,38,39,40,41,42,43,44,45,46,47,48 and 49 okay

tkx Kentaree your really helping cheers

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 16:02
Oops, forgot about that

Change the paste image line to:

paste image i+1001,pictures(i, xCoordinate),pictures(i, yCoordinate)

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 16:03
but keep everything else right

Newbie Now; Expert Later
Current project:The Sorus
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 16:09
still isn't getting it



where have i gone wrong

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 16:16
Well first of all the program could be shortened, just by increasinf the size of the array and modifying the one for...next loop to do the work of al three.

How many spaces do you want horizontally and vertically?
Also, could you tell me what error did you get or what went wrong?

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 16:33 Edited at: 14th May 2003 16:39
the error was image doesn't not exist and was found on the "loop" line

by space do you mean the number of spots if so its still 2x2
[_][_]
[_][_]

kay the idea of the game is to trade there only four images at a time to trade okay although 13 items altogeather okay

P.S. you helped me with the skysphere so how do i get the texture to rotate i tried "scroll object texture 60,5,0" but the texture just jumped back and forward from one spot and then i read the help it said the scrolling to perment so i tryed it while load the sphere and nothing happens kay

to speed it up do this right


like that right but that well paste them in the same place won't it

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 17:21
Hmm, sorry mate, I gotta go now, I might be able to help you later on. Just a quick help, dont bother rotating the texture in the sphere, rotate the sphere itself, its easier

Also, just try this:

for i=1 to 4
paste image i+1000,pictures(i-1, xCoordinate),pictures(i-1, yCoordinate)
next i

Talk to you later,
Kentaree

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 17:36
just for when you come back i try that i put yrotate object 60,5 in to my main loop but nothing happened. bye

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 20:47
Hmmm, right.
Just want to know, if your doing trading, I suppose you want random items/pictures in your choice menu? Just making sure, 'cos in that case we could use another array system, which is slightly more advanced, but would work well with random pictures. Just need to know so I can make a bit of code for you.

Cheers,
Kentaree

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 14th May 2003 22:43
what do you mean random pictures. each picture has its own varable using real number

13 all togeather if it is a 0 you do not have that item if you do the number is 1 kay there is probally some advance way using arrays to do that but this way it keeps it simple

crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 14th May 2003 23:36
Yeah, but what happens if you have more than four items? Do they not show in the menu? What I meant by random is that you said that 4 items will be displayed. My point is that you probably wouldnt start off with the same cards each time you play (of course I could be wrong, depending on the game ),and if that was the case, wouldnt it be easier to set up the program to accomodate for this.
Just trying to make both our lives a little easier

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 15th May 2003 00:40
no i check its not buying its trading to trade you must give them some thing and in return they give you something so you will never have more than 4 but you are right in the fact that the same item can appear in any of the 4 box during the game i depends on what items you have at the time
crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 15th May 2003 22:05 Edited at: 15th May 2003 22:08
Right, I honestly think this code'll work, if it doesnt, tell me, and I'll give myself a good whack across the head
I've started off a new code to make it more efficient and easier to
modify for use for your game.



Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 16th May 2003 01:25
okay first sorry but at the start you have no items and two where does the item apart from the start you are not mentioned it. i e-mail you a link to the first tech demo so you can see where this code fill fit in that might help

crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 16th May 2003 14:15
Okay, change the subroutine to:



With this, if itemsHeld(value)=0, it will not show an item in the menu, if there was a sprite there previously, it will hide it so you wont still have an item you dont have in you menu.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 16th May 2003 15:03
hey okay that work great but there is one part missing it is the part that works out which items are held i thought i would go sdomething like this



or should it be



so when you get an item in the game it will work out where there is a free spot and put the new item there and did you get the e-mail.
crystal

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 16th May 2003 15:27
Your first attempt was nearly right. The problem with it though, was that if there were more than 1 free spaces, each empty space would have been made to hold the item. By adding exit after you've found an empty space and filled it, you break out of the for...next loop so it wont continue after you want it to. It's a bit faster too.



As for the e-mail, yes, I got it, but I havent had time yet to download the demo, I'll see if I can download it later today. Stupid 56K .

Anyway, I'm happy it works now, I was eager to show I could program after being in extremely bad form yesterday , guess I havent lost it

Cheers,
Kentaree

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 16th May 2003 15:37 Edited at: 16th May 2003 15:39
56K is bad
i use cable (helps to have a dad who loves computer almost as much as me)
its 4mb compiled kay
yeah with this code over 2000 lines yeah

Newbie Now; Expert Later
Current project:The Sorus
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 16th May 2003 15:57 Edited at: 16th May 2003 15:59
it kinda works in the full game, is the first bit was in a little plan programme to make sure the menu code works now i have put it into the full fame instead of pasteing the image it pastes the matrix texture, and the


kay what is the item array used for because it is dimed at the start but that it it seems kinda pointless, have you put items instead of item some where look over it
kay

Newbie Now; Expert Later
Current project:The Sorus
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 16th May 2003 16:03
another error in the code found you have put in the code to take the sprite off the matrix texture stayes there i think i can do this but just incase

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 16th May 2003 16:23
No, the item array is actually very usefull, because it holds the image number of each one of the items, so item(0)=1001 means that item(0) uses image number 1001, and if you change the image numbers you use for each item, you change the values in the array, and the program will still works because it uses the image numbers from the array (*gasp*).

I dont understand your second problem, I think you mean the sprites wont hide?

Whatever I did I didn't do it!
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 16th May 2003 16:29
Yep, I think I see what the problem is

change the sprite command line in the subroutine to:


This actually demonstrates where the item array comes in useful. The itemsHeld array holds the item number you are holding. The item array contains the image number, so combining the two like above gives you the image number, which is needed for the sprite command.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 16th May 2003 16:43
thought so
any way what i mean is if you go into the menu and then come back out the images of the image stsy there so you have to go around the world map with them there. the missing command is the command that takes them off when you exit the manu

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 16th May 2003 17:04
Well, thats easy enough. When you exit the menu (you'll have the code for that ) you just hide, or maybe delete (its up to you really), the sprites you used for the menu. If the sprite numbers are 1 through 4, use something like

for i=1 to 4
hide sprite i
//or
delete sprite i
next i

And put it that this happens everytime you exit the menu.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 16th May 2003 18:22
kentaree it now come up with the error "array accessed out of bound" at the



section what should i do

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 16th May 2003 23:51
Hmmm, strange. You didnt put in 14 for itemsHeld() or something? As far as I can see from the code, the value of
item(itemsHeld(items-1)-1) does never go under 0. Actually, make sure tha the lowest value of itemsHeld() is 0, because if it is a negative number, you'd get that error. The other possibilty you'd get that error would be if the value went above 13, as there's only 13 spaces in the array for the items.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 17th May 2003 02:11
no


is it the fact that the item array numbers are too high

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 18th May 2003 23:26
Sorry for taking so long to reply.

I tried the code and it works for me. Try using just the code I have above, beforehand loading the images and try changing the values. If it doesnt work then tell me, 'cos it did for me.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 19th May 2003 19:49
i found one problem myself. i had done this


durrr with the gosub forest before its never going to get there

Newbie Now; Expert Later
Current project:The Sorus
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 19th May 2003 20:30 Edited at: 19th May 2003 20:40
first attempt work now for full intergration. yes kentaree it looks like you final got in.
thx
*edit one problem found in the delete bit needs an exit
okay getting the first item work fine well done
but the tradeing bit doesn't (i don't think the computer i picking up the fact that you are getting rid of the old item)

and my delete code isn't working it will work once on each item and then the second time you open the menu i will stay there the code is



do i just need to increase the number of cycle.

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 20th May 2003 00:11
Right, on your first snippet I saw another mistake you made. The itemsHeld() array should not be assigned a value of an item() array, but an item number, from 1-13. The program itself will find the item() number associated with it, and if you dont watch out, this could give you errors.

For the delete sprite error, it kind of puzzles me. Everytime you call the menu, it should set up the sprites starting at 1 and going up to 4, so if you call for...next loop afterwards it should delete them. Maybe try something like putting
hide sprite i
before the delete sprite i command to hide the sprites before they are deleted.
Tell me if it works.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 20th May 2003 00:31
for the trading bit i think its coz it prog is not deleteing the old object and replaceing the it with the new won.
this is the first code where you get an item


this is the code for the trading bit



it need to delete the old item

Newbie Now; Expert Later
Current project:The Sorus
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 20th May 2003 01:35
Okay, the problem here is that you prog is looking for an empty space, if it finds none, you dont get the item. What you have to do is find the itemsHeld() slot which contains the item you are trading, so lets say that is slot number 3, and you're getting item number 12 in its place. You'd use

itemsHeld(2)=12. This will delete the old value of itemsHeld(2) and replace it with the new one. Then you run your sub-routine to replace the sprite and presto, you have your new item.

Again, let me remind you that if you havent changed my code, then dont give itemsHeld() values from items(), as the items() array contains image numbers used only by the sprite subroutine.

Whatever I did I didn't do it!
ClearCoder
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 20th May 2003 17:22
okay so some thing like this



Newbie Now; Expert Later
Current project:The Sorus

Login to post a reply

Server time is: 2025-05-18 04:42:16
Your offset time is: 2025-05-18 04:42:16