Data type manipulation
Displaying 1-14 of 14 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Omni

Arrays, structs, multidimensional arrays.

Can you use them as arguments for functions?
Can you return them from functions?
Can you declare them locally in functions?

Posted on 2004-06-10 01:28:16

mcgrue

no, no, and no.

Sorry.

Posted on 2004-06-10 02:07:42

Omni

...
...
...

Right.

...
...
...

Any workarounds? Can you use DMA to send the address of an array or struct to a function? Or should I just make a big global array of everything I want to be able to use inside functions?

Posted on 2004-06-10 02:14:06

Zip

Not sure how useful this will be to you, but I've got a lack-of-references work-around that might help you. In fixing stack for my card thingy:
struct stack_instance

{
int next[MAX_ITEMS]; // Next item in stack
int item[MAX_ITEMS]; // Card identity
int free; // First free item
}

stack_instance stack;
int ref_first; // First item
int ref_last; // Last item
int ref_count; // Count of items

Then to call functions:
	StackConstructor();

ref_first = player.item_first;
ref_last = player.item_last;
ref_count = player.item_count;
StackPush(43);
StackPush(21);
player.item_first = ref_first;
player.item_last = ref_last;
player.item_count = ref_count;

Then in the function use as if you passed it:
void StackPush(int push_card)

// Add event to the stack
{
int push_this = stack.free; // Push item in first free slot
if (push_this == MAX_ITEMS) // If there are no free spaces in the array
exit("Stack overflow!"); // Exit with overflow error
stack.item[push_this] = push_card; // Sets the card
if (ref_last != MAX_ITEMS) // If this isn't the first item
stack.next[ref_last] = push_this; // Set previous next to new item
else
ref_first = push_this;
ref_last = push_this; // Set new item to last
stack.free = stack.next[push_this]; // Sets first free item to next free
stack.next[push_this] = MAX_ITEMS; // New last item points nowhere
ref_count++; // Increases item count
}

You could use this kind of method to pass/return anything you want - have one global array to dump/retrieve values.

Rar

Posted on 2004-06-10 02:45:23

gannon

or you can use my PStringList that can be passed into and back from functions, and declared localy, and can be treated as a array
if you are consitant you can even treat it as a array of structs (this takes some doing though)

Posted on 2004-06-10 03:05:19

Omni

String list. That reminds me, because I thought of this at some point.

What is the maximum size of a V3 string? If it's only 256 characters, a string list might not be too useful.

Posted on 2004-06-10 03:22:09

Zip

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

No such problem. If you're going to be calling the functions a lot though, I'd think twice about strings, as processing them tends to be a little more intensive than ints.

Rar

Posted on 2004-06-10 03:26:37

Omni

What if you make a simpler version of your global list?

#define someElements (somenumber)

datatype SomeData[someElements]

int GetNewDatatype()
--return the ID of the first unused member of SomeData

void ProcessData(int ID)
--pass it the address in the SomeData array, and it will process the data there.

int CreateSomeData()
---returns the ID of the newly created data.

Thus you'd manage data and pass it to functions by providing an address from a global array. I THINK this is similar to what you're doing.







Or, how about you just have two global variables that are used for function parameters? Like in assembler, where you can't pass arguments.

somedatatype [FUNCTIONNAME]_arg1
somedatatype2 [FUNCTIONNAME]_arg2

somedatatype3 [FUNCTIONNAME]_returndata

void FUNCTIONNAME()
---use the arg1, and arg2 datatypes as arguments. They could be any datatype you want because they are global.
If you want the function to return a datatype, create a global instance, and fill in the data inside the function (this requires advance notice of what datatypes you want to use, but isn't any different from normal C).



Personally, I like the second method. It works in all cases and doesn't have a wonky container array that can get screwed up.

Posted on 2004-06-10 03:31:30 (last edited on 2004-06-10 03:32:56)

Zip

Probably depends largely on what you are planning to actually do. Some kind of array/stack thing will probably work best if you are going to be doing a lot of similar things in sequence, but get more exotic and squished strings or something might be the only practical method. Not sure how verge legal that second piece of code is - but I might be missing the point.

-Small number of similar values: Dump to globals then retrieve
-Lots of similar values: Set them all into an array (in one go ideally) then run from there
-Weird, funky range of stuff: Use some custom function within each func. to separate out a compound string or something.

Rar

Posted on 2004-06-10 03:48:15

Omni

I really like the second idea. Can a function edit global variables?

Also, Zip, as a closer to this thread, how can I access the bonus on your compo piece? All I get are those cards. Spazzing on shift, home, end, space, enter, and alt doesn't do anything.

Posted on 2004-06-10 03:52:41

Zip

bonus.exe - separate program. Perhaps I shoul have been clearer,

As far as I've seen, all globals in verge are universal - any code anywhere can use them however they want.

Rar

Posted on 2004-06-10 04:03:11

Gayo

I would kill to be able to pass structs or even just variables by reference via DMA, but vecna has hidden all the pointers where no one can touch them, because he is mean.

Posted on 2004-06-10 04:08:52

Omni

Well, I guess it's not exactly a life or death thing, because you can get around it... I'll take what I can get though, so I guess if one-level nesting is the best they can do, I'll try and work with it.

Oooh. That bonus is pretty nifty. What's with the white square above the hill?

Posted on 2004-06-10 04:36:29

Zip

Indicates where (rather lame) light source is. Enter toggles it on/off - hold Caps then arrow keys move it around - I was running out of buttons. :)

Learning OpenGL has eaten some of my verge-ing time, but after I've finished this essay I should be writing tonight, I have lots of lovely free time. :)

Zip

Posted on 2004-06-10 04:48:45


Displaying 1-14 of 14 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.