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 Professional Discussion / Using Variable names in a sprite command

Author
Message
rolo9
16
Years of Service
User Offline
Joined: 1st Jan 2010
Location:
Posted: 6th Jul 2012 19:14
Is there a way to use a variable name instead of just an integer number? I tried SPRITE SprNumOne, 50, 50, 1 and the compiler said sprite did not exist. I assigned it SprNumOne = 1 before I used the sprite command. If I can't then I can't but I am hoping someone out there knows why.
Marabas
15
Years of Service
User Offline
Joined: 12th Dec 2010
Location:
Posted: 8th Jul 2012 02:10
You are right, declaring it first will work so

SprNumOne = 1

will allow you to use

SPRITE SprNumOne, 50, 50, 1

later in your code. If you want to be able to use the sprite in functions as well, you will have to make it a global variable like

Global SprNumOne = 1

Signature removed by moderator. Please do not give out the meaning of life in an open forum.
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 8th Jul 2012 03:38
Like Marabas said, you can use a variable (which can be an array or a user defined type) for sprite numbers or any other type of media for that matter.

If you've tried it but are getting errors then there is something else wrong with your code. Maybe if you post it then someone might be able to sort it out for you.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 8th Jul 2012 05:39
Also, if you are planning on adding and deleting lots of sprites in your game then you might want to try IanM's Matrix1 Utils which has a lot of useful functions for finding free ID's for Sprites as well as images, 3d objects, sounds, music, memblocks, etc...

ie:


Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
rolo9
16
Years of Service
User Offline
Joined: 1st Jan 2010
Location:
Posted: 8th Jul 2012 21:45
Thank you everyone. I was also trying to use use a sprite width command before I called the sprite the first time. That is why it didn't let me use a variable name.

sprite pic1, 50 - sprite width(pic1), 50, img1

I goofed because I have to call the sprite at least once like this:
sprite pic1,50, 50, img1

then I can make a variable

PicX = Xpos - sprite width(pic1)

Thank you for all the replies.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Jul 2012 21:36
Quote: "1) Dynamic Media Handling
Dynamic Media handling allows you to work in a faster way. Instead of creating media using the default DarkBASIC Professional commands (that forces you to define a number to each loaded media), you can now receive a media ID from the commands. This allows for a smoother code organisation, and a more intuiative way of naming media. All other commands in the eXtends plugin use the Dynamic Media Handling method to avoid conflict with user coding. Plenty of example source code is provided."


eXtends

some things still work and very handy!!!

Login to post a reply

Server time is: 2026-07-07 19:10:20
Your offset time is: 2026-07-07 19:10:20