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 / Local variable to type variables Identified by parameter

Author
Message
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 25th Dec 2010 16:14
I have a function that reads a text file. That local data needs to be read and stored into the variable declared as a certain type. However this function needs to put data into other variables of that type. It identifies the varibles of that type by a parameter passed to it. What would be the best way to identify those variables by a parameter.
The only solution I can think of is just to store the values in a global array of that type and then manually assign the values at each index to the types. THe problem with this is that I will have a veeeerrrrrrrry long "Select Case Endcase" statement.
Is there a better way??

My computer surpasses all the technologies of the day. What computer do I have?

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th Dec 2010 18:10
Why not post what you have so people can see if there's any obvious improvements, rather than guess.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 25th Dec 2010 19:50 Edited at: 25th Dec 2010 19:51
I don't really see what the problem is? What I would do, when reading the text file, is find out the values of:

what type the data is
value 1
value 2
...
value n

then have a select/case or a bunch of ifs, so

if type=vector
storage.x=value 1
storage.y=value 2
endif

etc.


Uhh... that's what you meant, right?

[edit]
oh wait do you mean you have a bunch of different named local variables? Like
health : armor : x : y : x1 : x2 : blah : foo : etc...

that all need to be given values?
I'd still say the same thing...

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 26th Dec 2010 00:17 Edited at: 26th Dec 2010 05:33
What I'm using it for is loading a text file storing texture info such as scale, mitmap flags, and texture properties. This info is read into a variable of the texture type I made. However this variable could be Stone, Brick, Grass, Dirt, ect... of the texture type. So I'm using a function that opens the text file passed through the parameter, and reads the text file data into the variable of type Texture. So for example:



But somehow it needs to know what variable to use. It needs to know that I want to store the Xscl in Dirt. I have no efficient way of doing this though. I would need to do:



But if I have 500 textures, this is not really feasible unless I want to spend 8 hours copying, pasting and typing each variable.
In C++ the solution would be simple, have the function accept a parameter that points back to the variable passed.
This would be a short example of what I'm trying to acheive in C++.

However Dbpro is not c++...

My computer surpasses all the technologies of the day. What computer do I have?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Dec 2010 12:18
Pass by reference is basically pass as array index in DBPro.

Example:


Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 26th Dec 2010 17:26
Okay thanks, worked perfect.

My computer surpasses all the technologies of the day. What computer do I have?

Login to post a reply

Server time is: 2026-07-21 20:35:13
Your offset time is: 2026-07-21 20:35:13