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 / User type With string var

Author
Message
farmkid4
16
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 17th Jan 2012 00:22
Hello guys its been awhile since i have used dbp but i have a little project that i am working on over the winter and i have a question that i would like some help with.

So if i have a user defined type such as

Type Player
Id as string
Gold
ArmyUnits
Color
endtype

with this info in it
//information for player 1
Player1 as Player
Player1.Id = "1."
Player1.Gold = 0
Player1.ArmyUnits = 2
Player1.Color = 3

could i access the information in Player1.Color like this?
Tmp$= "Player" + Variable$(=s 1.)
Tmp2=Tmp$.Color

So would Tmp2 be equal to 3?

I am trying to figure out if it is possible to use variables in this way. Thanks for the help.

Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 17th Jan 2012 00:30
Quote: "could i access the information in Player1.Color like this?
Tmp$= "Player" + Variable$(=s 1.)
Tmp2=Tmp$.Color"

The short answer is no. I'm not actually sure what you're trying to do.

The only way to access an object's members is like this.
Tmp2 = Player1.color

farmkid4
16
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 17th Jan 2012 00:35
Ok thank you for the quick answer.

I will try to explain better.

I was trying to use a string variable added to another string variable too get information out of a tpye.

The large picture is im trying to do a turn based game but I am having trouble getting an idea of a good effective way to go about switching players.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Jan 2012 00:39 Edited at: 17th Jan 2012 00:39
Use arrays.



TheComet

farmkid4
16
Years of Service
User Offline
Joined: 23rd Sep 2009
Location: on my pc :)
Posted: 17th Jan 2012 00:44
Thanks for the tips I'll change some things and see if i can get it

Are there any threads/tutorials on turn based games?
I did a bit of searching but didnt find much.

Thanks again.

Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 17th Jan 2012 03:13
Quote: "I was trying to use a string variable added to another string variable too get information out of a tpye."

It doesn't quite work like that.

Taking TheComets example with the array, you could have each player's assets (health, score, position etc) stored under a single index and then change the index when necessary. A small example:



Basically, you change the index of the array to change the player.

Login to post a reply

Server time is: 2026-07-10 15:30:30
Your offset time is: 2026-07-10 15:30:30