Dynamic Arrays in Verge?
Displaying 1-13 of 13 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Goldengamer111

I am creating a Pokemon game (don't worry - it's just for me and my family), and am creating an "engine" for it from scratch. Unfortunately, the line of code below is giving me problems. Every line that begins with a Method seems to make VERGE expect a "]", but see a ";". Does VERGE not support dynamic arrays?
struct PokemonOnRoute
{
Method Walking[];
Method Surfing[];
Method OldRod[];
Method GoodRod[];
Method SuperRod[];
};

On a side note, would it be safe to distribute my code (after I get it done), or might I get into trouble?

Posted on 2009-02-24 10:15:48

pthaloearth

no dynamic arrays in verge.

also no ; after the }

Posted on 2009-02-24 11:27:42

Goldengamer111

Drat. Thanks for telling me, though. I will try to find something else to use (gannon's Dynamic Array, perhaps? I'll look around).

EDIT: That file looks like it might work, but how do I use it? There, unfortunately, doesn't seem to be much documentation about it.

EDIT 2: This is getting off topic, but I have reorganized the layer list in my maps to "Layer 0, Entities, Layer 1, Special: Retrace, Obstructions, Zones", in order to allow my characters to walk underneath the objects in Layer 1, meant to be above everything else (like roofs and treetops). Unfortunately, when I run the game, some of the objects are not being rendered correctly. For example, off to the side of one of my maps is one of the rocky outcrops. I have a few different versions of the rocks, one on ground level (showing some grass around the edges) and one on top of other rocks (looking like it's part of the rocks it's resting on). On the bottom row of this plateau, I have some tree tops on Layer 1, but everything else is on Layer 0. Everything renders correctly in MapEd3, but when I load it in my game I cannot see the treetops and the rocks that should appear as on top of other rocks are surrounded by grass. Everything else on my map is working nicely, so why is there a problem with this?

Posted on 2009-02-24 12:25:47 (last edited on 2009-02-24 15:20:47)

Code

I've never used that Dynamic Arrays "package" before, so I'm not much help there.
But LuaVerge is another option that might fit your needs. It makes extensive use of lists, which provide all the functionality of dynamic arrays in a term that rolls right off your tongue.

http://www.verge-rpg.com/boards/display_thread.php?id=132594

Posted on 2009-02-24 15:08:28

Goldengamer111

Thanks for the link, but part of the reason I chose Verge was because of its simpler language. I don't think I'm up to coding this in Lua yet.

Posted on 2009-02-24 15:26:17

Overkill

VergeC has no language support for dynamic arrays. But there are a few ways to get around this!

1) (Most recommended, simple, not space-efficient) Just make your arrays have a reasonably large size for your purposes. Design it so that you have enough space for everything. If you find your game needs a bigger array, change the max array size later.

Just #define MAX_WHATEVER_SIZE for your whatever[] array, and change that as you go.

2) (New method, medium challenge) Use dictionaries. You can store list-like things in dictionaries, with a bit of work. Dictionaries being a type of array that maps a string key to a value.

Creating an empty dictionary is as simple as:
int dict = DictNew();
So you can set something in the mock array like this:
int i = 5; // Index to poke at in the dictionary.
DictSetString(mock_array, str(i), "Dennis"); // Sort of like mock_array[i] = "Dennis";
You would need to store a "size" in your dictionary somewhere too. But you can mockup dynamic arrays this way, I guess.

3) (Old way, advanced) Use malloc, and DMA related variables. You can allocate a pointer, and then manipulate dma.byte[], dma.sbyte[], dma.word[], dma.sword[], dma.quad[], et cetera.



Adding dynamic arrays directly into VergeC would be way too painful. Plus we're trying to keep the language somewhat simple. This is one of those limitations.

If you require flexible scripting, LuaVerge is still quite easy and it gives you all sorts of flexible data structures, being that Lua provides a bunch of this great functionality builtin. The code runs a whole lot faster, too! And once you get over the initial hurdle of learning Lua, it flows quickly.

But, if you for some reason are averse to learning Lua, I recommend option 1) or 2). These are the best options you're going to really get. Neither options 2) or 3) give a way to store structures in them. And 3) also can't store strings.

So option 1) is the least work-arounds, really. And think about it, for the original Pokemon games, there's probably like 8 different pokemon types tops in an area for each capture method (Walk, Surf, Fishing, Deep Grass), with the odd rare ones. Then they just split up each map into a bunch of different capture areas. You can make your game events change the contents of the capture arrays at every step, and possibly reserve the value -1 to mean no pokemon in a capture method's slot.

Posted on 2009-02-24 18:00:28 (last edited on 2009-02-24 18:45:04)

Overkill

Quote:Originally posted by pthaloearth

also no ; after the }
Actually this is one of those weird cases that is allowed by VC. This way people coming from a C background, where a semi-colon is needed after struct definitions are still satisfied. The compiler itself handles the optional semi-colon as a special case (with no difference other than that).

Posted on 2009-02-24 18:11:11

Overkill

Quote:Originally posted by Goldengamer111

EDIT 2: This is getting off topic, but I have reorganized the layer list in my maps to "Layer 0, Entities, Layer 1, Special: Retrace, Obstructions, Zones", in order to allow my characters to walk underneath the objects in Layer 1, meant to be above everything else (like roofs and treetops). Unfortunately, when I run the game, some of the objects are not being rendered correctly. For example, off to the side of one of my maps is one of the rocky outcrops. I have a few different versions of the rocks, one on ground level (showing some grass around the edges) and one on top of other rocks (looking like it's part of the rocks it's resting on). On the bottom row of this plateau, I have some tree tops on Layer 1, but everything else is on Layer 0. Everything renders correctly in MapEd3, but when I load it in my game I cannot see the treetops and the rocks that should appear as on top of other rocks are surrounded by grass. Everything else on my map is working nicely, so why is there a problem with this?
Hmm, odd. Did you make sure you saved your changes before opening the map with Verge? Also, Verge won't update a map that has been saved to while the engine is using it.

Additionally, there are some quirks in how MapEd renders some things. If this problem hasn't disappeared, maybe I can ask for screenshots. You know, Alt+Printscreen, paste into paint program, save as a PNG, host on imageshack.us or xs.to or photobucket.com or similar.

I can help more if I can see what it is you're trying to do, at any rate.

EDIT: Quote:Originally posted by Goldengamer111

On a side note, would it be safe to distribute my code (after I get it done), or might I get into trouble?
You won't get in trouble at all.

In fact, distributing games is encouraged! But, if you make a demo, feel free to post it here too! :D

We'd love to see a Pokemon game in Verge. Demoes are always cool.

Posted on 2009-02-24 18:20:44 (last edited on 2009-02-24 18:35:32)

Goldengamer111

I just double checked the map, and found that Maped was rendering the map like the game was. I fixed it and reopened the game, and it now works.

Quote:Originally posted by Overkill

You won't get in trouble at all.
That's good to know, but, just to check, you did mean that I wouldn't get into trouble with Nintendo either, right?

Posted on 2009-02-25 20:01:56

Overkill

Okay, now that I can't prevent.

I guess I'd recommend maybe just make sure your game isn't an exact copy of Pokemon? Maybe, similar battle systems and all that, but add your own custom monsters too and at least different game title (ie don't put Pokemon in the name :D)!

If it's a direct copy of one of their games, they can give a Cease & Desist to you, I guess. But if you have your own fresh content and name it something different, it should be spared from Nintendo's intellectual property lawyers.

Posted on 2009-02-25 20:12:42 (last edited on 2009-02-25 20:18:05)

Goldengamer111

What about just posting the code that is used to run the game, and not actually anything that could just be copied and ran? Basically, if I upload all the functions that would allow, for example, the populating of a route with Pokemon, and then accessing those Pokemon when a battle starts, without including the map or system (it would be in its own file) codes, might I get into trouble? I am currently only planning to use numbers to access Pokemon (e.g. 151 for Mew), and that and everything else could be adapted very easily into a game resembling Pokemon, but still being very different. Might I get into trouble then? I would really like to avoid even a Cease & Desist.

Also, I think I might check out scripting the game in Lua. I have started converting my code to Lua, but how do I use structs and ints in it? I am using Notepad++ (I got it when I saw that either that or Textpad was recommended, and before I saw how many people recommended Textpad instead), but it is not highlighting either word. Finally, how do I create and change the size of a dynamic array (I also have to be able to clear it)?

EDIT: Mew is #151, not #101.

Posted on 2009-02-25 21:29:06 (last edited on 2009-02-26 07:36:34)

Overkill

Ehhh, code without game isn't that useful. I mean, really, even though there's a CHANCE Nintendo could get angry at you for making a game, I doubt they care given the tons of fangames made all the time. I guess just, if you get a C&D, change your development? :D

Here's a quick Lua rundown if you wanted to go through http://www.bananattack.com/vx/Learn_Lua

Okay, and as I was saying earlier, VC doesn't have dynamic arrays. I proposed alternatives though! I'll explain, by giving you some possible code that I'd use to make a system like this.

Guranteed it's a little hacky, but it might get you started. (Untested though)
#define MAX_POKEMON 151
struct Pokemon
{
// SIMPLIFIED FOR SAKE OF EXAMPLE
string name;
int hp, maxhp;
}
Pokemon pkmn[MAX_POKEMON];


#define MAX_PKMN_PER_METHOD 16

#define MAX_CAPTURE_METHODS 5
#define METHOD_WALKING 0
#define METHOD_SURFING 1
#define METHOD_OLD_ROD 2
#define METHOD_GOOD_ROD 3
#define METHOD_SUPER_ROD 4

struct CaptureMethod
{
int count; // The number of pokemon that can be captured by this method.
int slot[MAX_PKMN_PER_METHOD]; // The ID of each pokemon that can be captured by this method
};

CaptureMethod methods[MAX_CAPTURE_METHODS];

// Adds a pokemon to be captured by a certain capture method.
// Method index is one of the defines above.
// Pokemon index is the number of pokemon in the pokedex.
void AddPokemonToMethod(int method_index, int pokemon_index)
{
int count = methods[method_index].count;
if(count > MAX_PKMN_PER_METHOD)
{
Exit("Out of pokemon slots on the capture method!"
+ "You need to up the max number of pokemon per method,"
+ "or remember to clear your pokemon list.");
}
methods[method_index].slot[count] = pokemon_index;
methods[method_index].count++;
}

// Call this each time you switch areas, and want to change what can be captured for a certain method
void ClearMethod(int method_index)
{
methods[method_index].count = 0;
}

// Call this when you want to clear everything.
void ClearAllMethods()
{
ClearMethod(METHOD_WALKING);
ClearMethod(METHOD_SURFING);
ClearMethod(METHOD_OLD_ROD);
ClearMethod(METHOD_GOOD_ROD);
ClearMethod(METHOD_SUPER_ROD);
}

Posted on 2009-02-25 23:02:24 (last edited on 2009-02-25 23:05:33)

Goldengamer111

Thanks. I will definitely keep that code in case I switch back, but I think it might be somewhat nice to code a game in a "actual" programing language, for once. After looking through it again, Lua doesn't look that hard, either. However, I am still not completely sure how to run a zone event (function name_of_zone as its title?), and would I be able to put that code in one of the global codes and be able to run it without typing it into every map? Finally, how likely would it be for Nintendo to give me a Cease and Desist for distributing code that runs the game, but which nothing but the names of the functions pins it down as for a Pokemon game? I am only planning to give this to my little brother for his birthday, and, at the moment, have no plans to give the game to anyone outside my family, and definitely not to sell it. If you want me to, and if you think that Nintendo wouldn't mind me posting it, I might upload the code, though.

EDIT: Been meaning to ask this for a while, but is it possible to access the system time from Verge? Also, how would I go about updating it?

EDIT 2: I have gotten the game to open without giving me an error, but the game closes as soon as the "loading" screen goes away. What is happening here?

EDIT 3: I have returned to VergeC, and, so far, your code works nicely. I have slightly edited it, to fit better with the rest of the game, but I managed to get the game to run without giving me an error! I have copied the Lua files to a different folder, so, if I do ever want to switch back, I will not have to remake as much code. Thanks for all the help you have given me!

Posted on 2009-02-26 05:29:29 (last edited on 2009-02-26 08:49:17)


Displaying 1-13 of 13 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.