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 / Storing array value into string

Author
Message
badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 6th Aug 2010 05:57
I have the following array full of characters

map$(Int(curposx), Int(curposz))

I'm trying to clean up my code, so I'm trying to save the value of that array into a string variable like so:

mapchar$ = map$(Int(curposx), Int(curposz))

But I get an undefined array error. What am I doing wrong?
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 6th Aug 2010 06:02 Edited at: 6th Aug 2010 06:08
try removing all the Int's

that's assuming curposx & curposz are integers...

see, INT is a reserved word but, in your context:

mapchar$ = map$(Int(curposx), Int(curposz))

i'd bet the compiler is expecting Int() to be an array. probably a glitch but you're definitely mis-using Int.

Virtual Nomad @ California, USA
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 6th Aug 2010 15:50
I'm using the large dungeon logic, so those values are real values. I'm using Int to get the interger values and then those integer values to find the current map value. Those values are "#", ":", ".", etc. Each character represents different parts of the map, like "ceiling", "wall", etc. I currently have code like



So, I'm trying to clean it up to make it easier to follow by saving to a variable first, and then using that variable in my code, like this:



But I get an error on that first line about a bad array.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Aug 2010 18:58 Edited at: 6th Aug 2010 18:59
Yeah, Virtual Nomad is right. Using INT on a variable that should already be an integer is just redundant.

Quote: "But I get an error on that first line about a bad array."


If you dimensionalized the array smaller than curposx and curposz then it should error out because it's looking for a bigger array. On the lines following that first line you need to add a $ to each mapchar to make it a string.

Using strings for a map is a decent method but it's better to use numbers instead since it opens up more options. Using strings you're limited to 255 different map objects (using single characters) but with integers you're limited to a bit over 4 billion different map objects.

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 6th Aug 2010 22:03 Edited at: 6th Aug 2010 22:44
I also used the huge dungeon tutorial as a starting point for my dungeon game, so I know what you are trying to do.

This code works fine...



As you can see, you don't need to use int() on the cursorposx or cursorposz values, because array index values are always integers. DBPro converts them as needed.

But you cannot use mapchar instead of mapchar$. I suspect you are NOT doing this, but simply mis-typed it in the code box.

Arrays default to being global, so unless you explicitly defined map$ as local, scope is not your problem, as illustrated in this code...



If you had used a value that was outside your array dimensions, the error would have been just that - "Runtime Error 118 - Array does not exist or array subscript out of bounds at line xx", so that's probably not your problem.

An error indicating an undefined array would suggest you look for an array that you have not defined, either in the line indicated, or as often happens in DBPro, look in the lines just before what the error code says. Either way, without seeing your code, we're all just guessing.

EDIT: looking at the code in your other thread, I didn't notice any undefined arrays, but I can't check it until I get home from work. Post your cleaned up code, and I *can* look at it while I'm at work.

badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 10th Aug 2010 05:22
Here's what's I currently have that works



If I changed it to this:



All I'm trying to do is store the value of the array into a variable. It almost seems as if it's trying to store that array into another array.

Grog: It's my first game, so I'm keeping it simple. If I use characters, then I can simply edit the maps using a text editor and use # for walls, M for monsters, U to go up a level, D for down, etc. Maybe in my next game I will use integers and build an editor to draw out the map and save everything as integers.

Rich, I'd love to see what you are doing with the dungeon code. I've make it so I can create the maps and slide along the walls. If I place a U on the map, it goes up a level, and D for down. So, now I have an unlimited number of levels I can create. Now I'm looking to take each level map and create monsters that hide in the shadows and attach when you get too close to them.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Aug 2010 06:52
Quote: "All I'm trying to do is store the value of the array into a variable. It almost seems as if it's trying to store that array into another array."


It shouldn't be... those code snips are virtually the same the only difference is you've shortened the code a bit using the variable. Something you may be interested in are SELECT/CASE statements. It's a list of possible outcomes without using IF/THEN statements.



Quote: "Grog: It's my first game, so I'm keeping it simple. If I use characters, then I can simply edit the maps using a text editor and use # for walls, M for monsters, U to go up a level, D for down, etc. Maybe in my next game I will use integers and build an editor to draw out the map and save everything as integers."


You can use numbers in text files too but it's ok. You're on the right track towards being a better programmer learning the simple methods first then the more advanced methods.

Login to post a reply

Server time is: 2024-11-16 15:33:02
Your offset time is: 2024-11-16 15:33:02