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 / Help and advice on udt's

Author
Message
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 18:13
I read up on UDT's in the hands on book and searched the forum but still have some questions. I want to make a create character system which I think I may be able to do with arrays but I think a UDT would be better. I have not really designed the UDT yet and am going to go play with some code to test out some things before I do it in my game. I thought I may ask some questions here and save a little time.

I am thinking that my create character system will be a function so should I make my UDT in the function? If I make it outside of the function will I still be able to access the type variables or pass the UDT or its variables to the function? If I make it outside of the function can I make a UDT Global? I may want to access these variables from other areas and functions in the program.

I will probably have 10 to 20 variables in this udt such as character name, rcae, class, hitpoints, strength, dextarity, luck etc... I am also going to want the program to edit the type variables when it needs to, like when the character levels up, or looses hitpoints. I am going to also want to save the character when it is created.

I have been thinking about this and I think I could just do this with a function and variables and no UDT but I think a type would be better since the character type would hold all the variables and I can create multiple characters using just the one type.

Any advice would be greatly appreciated!!!

Thanks
Dragonslayer
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Jan 2013 20:29
The UDT structure should be defined outside of functions. Also keep in mind that any UDT-based variable you create within a function cannot be returned from a function.

When you define a UDT variable, its scope is no different than defining any other variable.

If you plan on having more than one character, store them into an array. You can use the array commands to add new elements and create a UDT within a function. Using function parameters to set the values of the UDT then assigning it to a new element in the array. The arrays are global by default.




"You're not going crazy. You're going sane in a crazy world!" ~Tick
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 13th Jan 2013 21:25
I have been doing some reading and was kind of figuring this out on my own but you just made it a little clearer, thanks!!! I was also reading some stuff that makes me think I could just get by with array's only.
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 14th Jan 2013 01:58
When you look at saving, I was thinking to use an INI file... unless I figure out DarkDATA XD

Phaelax... That is interesting...

The thing that is new to me is > chars() as MyUDT < What exactly is this doing?

Thanks in advance

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 14th Jan 2013 17:00
Phaelax or anyone else who knows, I created a UDT with 17 Elements, Variables, Records or whatever you want to call them. Some are string and some are integer. I am getting what you said about the arrays,UDT's and Functions. I am not to sure about saving the characters in an array when you can only save one type to an array. How can I store all the characters stats which are INT along with it's name, race, class, items which are string?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jan 2013 21:47
Oops. I forgot a DIM in there valentine, that's all. Just defines an empty array.

I'll try to fill in the blanks with an example later after work. (ain't typing code from my phone!)

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 14th Jan 2013 22:47
I picked up on the dim but I still can't get it to work. Here is my code. I commented out most of the type variables and tried to just get a couple to work with the function and array.



No matter how I change things around I keep getting this error

Run time error 118 Array does not exist or array subscript out of bounds at line 27
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Jan 2013 04:46
Thanks Phaelax... awaiting your return I am still new to Arrays even though I can use them in PHP...

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Jan 2013 15:48
You're using the array incorrectly. Upon inserting an element in your function, at that moment the array only has 1 element total, index 0.

Character(0).name
Character(0).strength

My example left out the index in parenthesis because the array's internal pointer will be at the last inserted index already. So every time you use the function to add more characters you won't need to specify the index manually.

Then to print out the array (character data):

For i = 0 to array count(character())
Print character(i).name
Print character(i).strength
Next i

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 28th Jan 2013 01:33
Ok I have some code here and it does not work I keep having an error saying declaration not valid at line 4.

I have tried everything, the original name was CharacterType. I have capitalized type and endtype, left them small changed the type name and I can't get it to work.

Ones and Zeros
17
Years of Service
User Offline
Joined: 7th Jun 2007
Location: Western NY
Posted: 28th Jan 2013 04:04
I got your last code snippet to work by finishing your variables. You have hitpoints as int. Make it hintpoints as integer. Just finish spelling it out. Add the wait key and end so you can see it.

Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 29th Jan 2013 03:22 Edited at: 29th Jan 2013 03:26
How stupid of me, I am so used to putting int in front of variable names I just did it on the backside also! Thanks. I played around yesterday and got array's and UDT's working together woooohoooo! moving right along!!!

Login to post a reply

Server time is: 2024-11-23 13:42:18
Your offset time is: 2024-11-23 13:42:18