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 / Can you do this with a UDT?

Author
Message
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 18th Apr 2013 23:39
I have not had much time to work on this project. I would like to know if you can create a UDT in a function save all the UDT variables to an array then save what you created to disk then call it up later if needed?

I want to make a create character function. I want to make the UDT in the function. There will be a few options like pick your race, your class, and profession. Then roll for the attributes all at once. Not quite sure how I will get that to work but I will figure it out. After they roll for attributes they will be given an option to save the attributes or re-roll. If they save I am guessing I will be able to add the attributes the array with an add to array or insert into array command then after they are done creating this character I want to offer an option to save the character to disk and create another character. I want the player to be able to create 10 or 20 characters and save them. I want to have an option in my main menu to re-call the character's to view them and add them to a party. If they remove a character from the party that character should go back on the list with it's current stats. For that matter the characters should be saved to the character list at every save anyway.

So I am sure there are many ways to do this with UDT's and without, with functions and without. I would like to do it with UDT's, A function and array's if I can do it this way.

Some suggestions or tips from you much more knowledgeable coders than I would be more than welcome!

thanks much
Dragonslayer
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Apr 2013 00:33
Why create a new UDT in a function, just use the same UDT that you'd use in the rest of the game. Plus, I don't believe there's a command for saving UDT's. (Save Array doesn't work I believe)

Just instantiate the UDT in your main code... (for example)



This is a fantastically oversimplified way to do it, but it's how I'd do it.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 19th Apr 2013 00:51
I was not going to create a new UDT I just want to know if I can do it all within a function. I don't think you can pass a udt to a function but I am pretty sure you can create one in a function. Also you would not actually be saving a udt you would be saving the udt arrays which would be all the information for a game character.
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Apr 2013 01:00 Edited at: 19th Apr 2013 01:02
You can't pass a UDT to a function, but you can access it in one. And the save array command doesn't work for UDT arrays.

Why do you need a UDT if you're not actually going to use the details right away. You could just have a structured list of variables and just save them to an XML file or something. (Or maybe I don't fully understand what you mean...... )

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 19th Apr 2013 01:19
Actually, you can pass a UDT to a function, you just can't return one from a function:



[b]
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 19th Apr 2013 01:24
Well I didn't know that. (And still won't use it probably. lol)

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Dragon slayer
18
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 19th Apr 2013 01:57
Well like I said there are probably a number of other ways to do this. I could probably do it using a structured list of variables and then saving them.

I am thinking of ways to do it. I like the idea of udt's then declaring an array as the udt type then you can save the array with every piece of information for the character in the array. It does not matter if it is int or char it all gets saved in the array. Then that character(array) can be saved with all the character information and re-called later if the player wants to use the character.

If you can access the udt from a function then all the character creation can be done from within the function and this would work I guess.

I knew you could not return a udt from a function, that would be nice!

So if you can make a udt in the function and then set up your array as type do all the work to get the info into the array then return the array, character 1 or what ever the character's name is. Then make another character y/n if Y then the function does it's job again and returns the next character. If no then the game returns where it needs to go and then player continues on playing.

Later the player wants to play another character so he opens up the list(clicks an option) the character list loads from disk, he clicks the player he wants to use closes the list which saves back to disk and the player continues to play with the new character.
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Apr 2013 05:00
Furthering Diggsey's post, what you can do to pass UDT's through functions is make a passing variable. For instance:



"Get in the Van!" - Van B
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 19th Apr 2013 08:06 Edited at: 19th Apr 2013 08:11
Well now that you mentioned this question, I felt it would be a good excuse to write a tutorial. Although what I have discussed is something a bit more advanced than what you are asking for; however in a nutshell, load and save your UDTs using memblocks.

But if you want to learn some more, there is a small example in the tutorial which focuses on saving and loading arrays.

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 19th Apr 2013 18:21
Also it might be worth mentioning that for some reason you can't pass a UDT directly from an array into a function:



[b]
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Apr 2013 21:49
Quote: "Also it might be worth mentioning that for some reason you can't pass a UDT directly from an array into a function:"


I think I might've posted that in the bug board before.


Since everything is passed by value, has anyone tried messing with pointers?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 21st Apr 2013 05:47
Quote: "has anyone tried messing with pointers?"


Diggsey did it inside the TopGUI library.

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.

Login to post a reply

Server time is: 2025-05-18 02:32:54
Your offset time is: 2025-05-18 02:32:54