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 / I need variable help. More advanced variable help

Author
Message
The Lone Programmer
21
Years of Service
User Offline
Joined: 29th Jan 2003
Location: California, USA
Posted: 1st Oct 2003 05:16
Ok,
I haven't quite been able to figure it out. The variables I think I am using are the number sign variables(#).

Ok say I've got potions for my game. How would I make it so that whenever I recieve a potion it adds in my inventory. How would I make these potions have special attributes like how much they heal or when mouse moved over them it describes them.

What would be the number 1 variable tag to start out a potion command.

Give me some examples of # sign variables... It doesnt have to be potion related.

Thanks for the help.
Nicolas

Future Company Name = Blazing Fire
Current Website Name = Blazing Fire
Future Number is Eleventy
DrakeX
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location:
Posted: 1st Oct 2003 07:09
here are some # sign variables.

blah#
size#
thisisapoundsignvariable#

happy?

..

anyway there are 4 kinds of variables in DBP -- integer, float, string, and type.

integer variables have no symbol after their names. so x, y, numberofpeople are all integer variables. integers cannot have numbers after a decimal point. these are integers: -5, 12, 344, -452432. they are also more accurate when you get into bigger numbers (like 100000 and more).

float variables are the "# sign variables". they have a # at the end of their name. i put some at the top of this post. floats can have numbers after the decimal point, like 3.5 and 0.1123. however floats are not very accurate with very large numbers -- they go into something called "scientific notation" which looks like 5.34242e+014. confusing and inaccurate.

strings are text. they have a $ after their name. so name$, and command$ are string variables. they hold text, and when you give them a value you put what you want to put in them inside quote marks. so you do name$="Smokie McPot". there are a bunch of DBP functions and commands to manipulate strings. you can also add strings together, so "a "+"b" will give you "a b".

types are special variables that are what you're looking for. they allow you to have several variables in one thing. you first have to define the type, like:

type potion
name$, life_to_give_back
endtype

then you can make an array of types.

dim potions(10) as potion

then you have to assign the variables. you access the variables in types using a period like this:

potions(0).name$="Cure 1"
potions(0).life_to_give_back=10
potions(1).name$="Cure 2"
potions(1).life_to_give_back=30

and so on.

i just really hope these 10 minutes of typing were not in vain. which i have the unfortunate feeling that they were.

stop looking at me!
The Lone Programmer
21
Years of Service
User Offline
Joined: 29th Jan 2003
Location: California, USA
Posted: 1st Oct 2003 07:55
Hmm.... This part of the post is what relates to me I think.

Quote: "types are special variables that are what you're looking for. they allow you to have several variables in one thing. you first have to define the type, like:

type potion
name$, life_to_give_back
endtype

then you can make an array of types.

dim potions(10) as potion

then you have to assign the variables. you access the variables in types using a period like this:

potions(0).name$="Cure 1"
potions(0).life_to_give_back=10
potions(1).name$="Cure 2"
potions(1).life_to_give_back=30
"


So if I follow this code kinda similarly then it should work right? The name of the potion would be "Cure 1" and its value would be to heal 10 right? Is that where you were going at?

I appreciate the help. Maybe if you can get back to me.
Thanks
Nicolas

Future Company Name = Blazing Fire
Current Website Name = Blazing Fire
Future Number is Eleventy
skovron
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 1st Oct 2003 18:05
As for adding things, you dont need a const dimensin arrays, you may do following



Then to list all them you do:


And if you want to remove some potion from array you do:


Yeah with this you can dynamic add and remove potions to array but i think now you should get closer to DarkBasic types.

oh and try to ask some concrete questions and we'll try to help you
The Lone Programmer
21
Years of Service
User Offline
Joined: 29th Jan 2003
Location: California, USA
Posted: 2nd Oct 2003 01:15
Hmmm.. Very interesting code Skavron.
It appears to only work in my DBP demo right now. I own Classic and I hope to soon buy pro. Am I right or is it suppose to work in classic also.

In the code.. If I edit certain things in the code you gave me, would I be able to make it so my potion actually does work or do I need a lot more variable stuff.

In my dbp demo, when I execute the commands you gave it prints

0
Cure 1
20

How do I get it so that the zero does not appear? I try deleting the part:
next i
but it doesnt work after. What do you suggest? I want it to appear:

cure 1
20

At the minimal. My goal is to get it to acually do stuff.

Get back to me please
Thanks
Nicolas

Future Company Name = Blazing Fire
Current Website Name = Blazing Fire
Future Number is Eleventy
DrakeX
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location:
Posted: 3rd Oct 2003 04:19
"it suppose to work in classic also"

the dynamic array commands, like ARRAY ADD TO QUEUE are in DBP only.

"I try deleting the part: next i but it doesnt work after"

umm no offense but do you know what "next i" means? or does it all look like "variable stuff" to you?

it's printing that extra 0 because there is an unused element at the top of the array. so after the "dim potions(0) as potion" line, put "empty array potions(0)" and that extra element will disappear.

good luck on trying to get it to do stuff.

stop looking at me!
skovron
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 3rd Oct 2003 19:11
Yeah I am here.
I've forgotten empting the array, but anyway forget about dynamic arrays for now. All the stuff could be done using "normal" static arrays.
Tell what you wanna do for ex. with your potions and mayby I'll put some code.
But I must know exacly what you wanna do.
Oh and I prefer learn you using vars than give you fully working code to just copy-paste it.

Login to post a reply

Server time is: 2024-11-25 10:25:22
Your offset time is: 2024-11-25 10:25:22