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 / Inserting back into an array.

Author
Message
Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 16th Jul 2010 09:22
Okay so I am loading back an array with the following code,



How do I insert those values back into the array?

Whole code if needed,


Functions.dba shouldn't be needed...

Thanks!
Zeus

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th Jul 2010 10:55 Edited at: 16th Jul 2010 16:05
The first issue is we don't know how you saved the array. Since it's multidimensional I'm just going to guess that you looped through the first dimension then increase the second dimension when first reached it's max. So this is quite simple depending on how your array was saved:



If you stored it in the way I'm reading it then it should return back fine, if not, then I suggest altering the read order or how it's stored. Hope this helps

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jul 2010 15:33
A few No-No's here.... Indent EVERYTHING so it's easier to identify what's inside loop's and if's. You are declaring a global within an if-statement:


and unless keystate(19) is allways =1 (and it's not), you will be using it before the global declaration (and may be making another variable:

Some languages would automatically catch this mistake and not compile, but DBP has an automatic variable declaration system. This kind of stuff could get you into trouble and cause unexpected results that you might never find a solution for.

Now for your stated problem:
Sasuke is right, we don't know how you saved the data. Do as Sasuke suggested. Keep your read and write consistant.

The fastest code is the code never written.
Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 16th Jul 2010 16:22
It was in the full source...



Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jul 2010 16:59
Perhapse you should explain what you are trying to accomplish with your code.

It seems like...... Screw it!!!
You want to make a city grid right? You have the array set up with the info you want in it.... I would simply change it to:

Don't worry about saving any info until you exit the game or you can have a command within to save your progress. Save it like Sasuke said to read it: (I modified it to write)

Each time the player wants to change a plot, determine if it's occupied by using your code:

If it's not occupied:



Ultimately the method you are using now seems messy and I'm not sure you will ever get it to work the way you want..... If my suggestion doesn't sound like what you need, let me know..... and give me an outline of what you want accomplished in your game.

The fastest code is the code never written.
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 16th Jul 2010 17:21 Edited at: 16th Jul 2010 17:24
I usually do something like this:


But IanM recently made a great command for loading/saving UDT arrays (Get his plugin here if you don't already have it). It's basically a WRITE ARRAY TO FILE command, only it's called SAVE ARRAY TO DATAFILE instead. To load arrays saved using this command, just use LOAD ARRAY FROM DATAFILE. Keep in mind that you will have to use his datafile commands instead of the normal file commands if you want to use it. But his are very easy to grasp. If you were to save it in the same way you are saving it now, your above code would become this instead:


But using that LOAD ARRAY FROM DATAFILE command, you could just do this:



Of course, you would need to save it like this first:


Just make sure the array you are loading into has the same dimensions as it did when you saved it. Hope this helps

EDIT: IMPORTANT:
Your CityArray is Dimmed as a 10x10 array. I'm not sure if it'll work properly when saved.

But even if you didn't use IanM's commands, you can't just write cityArray().tileX=blahblah..., I think you have to write cityArray(x,y).tileX=blahblah...., where X and Y are the parts of the array you want to put the value into.

Zeus
20
Years of Service
User Offline
Joined: 8th Jul 2006
Location: Atop Mount Olympus
Posted: 16th Jul 2010 17:43
Thanks!

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Jul 2010 19:56
Quote: "you can't just write cityArray().tileX=blahblah"

Yes you can, and as long as you also advance the 'current' index of the array, it will load correctly too.

You can't modify the array using the list/queue/stack commands, but you CAN use the list commands quite safely:


Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 16th Jul 2010 20:31 Edited at: 16th Jul 2010 20:31
@IanM: Wow, I did not know that. Learn something new everyday .

@Zeus: No problem!

Login to post a reply

Server time is: 2026-07-25 03:25:49
Your offset time is: 2026-07-25 03:25:49