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 / What is wrong with this code?

Author
Message
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 01:36
I am making a very simple throwing system and for some reason when I try to paste sprite 4 anywhere it wont, it is like it doesn't even exist. Here is my code,



Why doesn't it work?


My next question, I was thinking of changing this system to where it actually moves sprite 4 across the screen to where you throw it. How would I do that?

Thanks much,
-->:Zeus:<--
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 18th Jun 2009 01:58 Edited at: 18th Jun 2009 01:59
First off, you never made p1weapon1$ be equal to "beachball" so it never enter the if part of the code.

To the sprite part of code:
When you are making a sprite here is the command

Sprite (image you are making the sprite from),(position x),(position y),(number of the sprite your creating)

Also when you are making a sprite, you have to create the sprite from an image, so you would have to get an image first.
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 02:03
Quote: "bballx=p1x+50
bbally=p1y

sprite 4,bballx,bbally,3
"


I created the sprite, plus there is a command called paste sprite. I have the image, I quoted it. Plus p1weapon1$ is set before the loop.
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 18th Jun 2009 02:08
is there anyway possible that i could see the whole code?
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 02:11


There you go.
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 18th Jun 2009 05:48
Try this:

Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 06:40
That still doesn't work and was basically the same code I was using?
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Jun 2009 11:27
Actually it's: SPRITE Sprite Number, X, Y, Image Number

There are a few things you need to change. Having a # after a variable makes that variable a real number (a number that can have a decimal point). Drop the # from the variables to make it a standard integer (a whole number) if you never intend that variable to be a number that uses a decimal point.

If the beginning setup of player 1 will always have p1weapon1$="beachball" then checking for it after checking if weapon 1 is selected would make it redundant. If you intend to change p1weapon1$ during the game then don't worry about it.

I suspect the sprite number 4 you're talking about is the mouseclicked sprite number 4 (and not the one next to player 1). The mouseclicked sprite is pasted to the screen... and since your main background (the stadium) is sprite number 1 you'll never see sprite 4 pasted. Pasting sprites puts a copy of the sprite on the screen and actual sprites are always above any graphics drawn to the screen. So it is pasting but because sprite number 1 is so big you can't see the pasted sprite under it. We generally don't use a sprite for a main background and just use PASTE IMAGE instead.



Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 17:00
Quote: "If the beginning setup of player 1 will always have p1weapon1$="beachball" then checking for it after checking if weapon 1 is selected would make it redundant. If you intend to change p1weapon1$ during the game then don't worry about it."


I intend on changing it.

Quote: "I suspect the sprite number 4 you're talking about is the mouseclicked sprite number 4 (and not the one next to player 1)."

Sprite 4 is the one in front of the player after weaponSelected1#=1 (it is the weapon). It then shows a cross hair (sprite 50) and wherever you click it is suppose to paste itself there (the system will be improved later but I was trying to do something simple).

Quote: "We generally don't use a sprite for a main background and just use PASTE IMAGE instead.
"

Thanks for solving my problem.


Last question, how do I make a system to where the sprite actually moves to where you clicked? You know like your throwing the sprite where you clicked? I will leave you alone after this lol.


Thanks!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Jun 2009 19:04 Edited at: 18th Jun 2009 21:48
Quote: "how do I make a system to where the sprite actually moves to where you clicked?"


Is that what you meant?
I haven't used curvevalue for a while and I just wrote this on the fly so sorry if it doesn't work.

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 20:25
No, it doesn't work and I can't seem to get it to. Any other suggestions? Thanks anyway though OBese!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Jun 2009 21:52
It works fine now. I just missed out the # when drawing the ball.
I knew it must have been something to do with drawing the circle because it starts off in the top left corner (0,0) even though I had given it an initial position (ballx# = 320, bally# = 240). When things come out as 0 that you didn't expect to it probably means you've typed a variable name incorrectly. Just a tip for when you're debugging your own code

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 22:26
Alright that code works and thank you very much. But I still have one question, what will I use to know the weapon has reached its target?

Here is what I have,



How do I know when to trigger bballactive=1 so I can cause the damage, explosion, etc? Does that make sense?

Thanks!
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 18th Jun 2009 22:38 Edited at: 18th Jun 2009 22:39
I just got in on this(and have only skimmed the code), but you should trigger bballactive when the coditions for impact(sprite collision,etc.) are met.

like....



Your signature has been erased by a mod because it was too big.
Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 18th Jun 2009 23:34
Okay but it is originally meant to only take 15 damage or 20 damage when it is thrown. When I p2health# it is in the negatives. Why is this so? I put my entire code below.



Thank you!
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jun 2009 02:16 Edited at: 19th Jun 2009 02:19
It's because even though the sprite is deleted the weapon selected is still 1 and the sprite is recreated on the last x and y it was so another collision detection is triggered over and over again. You can reset all the variables for the ball before you leave the IF/ENDIF of the collision detection. I also moved the crosshair outside of the weapon selection area (it wouldn't show up after the weapon was deselected).



Zeus
17
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 19th Jun 2009 02:50
I love you.

Not really, but I really like you now. Haha.
Grog Grueslayer
Valued Member
18
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jun 2009 03:04
Np. I just noticed I forgot to change the image loading back to the way your images are. I replaced all of them with numbers 1 through 9.

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 19th Jun 2009 13:50
Quote: "what will I use to know the weapon has reached its target? "

I gave you that. "targethit" will equal 1 if the ball has hit its target.

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer

Login to post a reply

Server time is: 2024-05-20 10:56:18
Your offset time is: 2024-05-20 10:56:18