GSVector documentation:
First of all let's take a look at the header file and the functions you can use:
Function:
function createGSVector();
Description:
Creates a new GSVector object and returns a pointer to it that you have
to store in a VAR.
Parameters:
none
Function:
function destroyGSVector(vectorPtr);
Description:
Destroys the GSVector object.
Parameters:
vectorPtr (var): the pointer you got from the create function
Function:
function insertIntoGSVector(vectorPtr,value);
Description:
Inserts a new entry to the vector. The entry is added at the end of the list.
Parameters:
vectorPtr (var): the pointer you got from the create function
value (var): the value to add to the vector
Function:
function getFromGSVector(vectorPtr,pos);
Description:
Returns a value (var) from the vector from the given position.
Parameters:
vectorPtr (var): the pointer you got from the create function
pos (int*): the position of the wanted value in the vector
Function:
function eraseFromGSVector(vectorPtr,pos);
Description:
Erases a value from the vector at the given position.
Parameters:
vectorPtr (var): the pointer you got from the create function
pos (int*): the position of the value to erase
Function:
function sizeOfGSVector(vectorPtr);
Description:
Returns the size (var) of the vector.
Parameters:
vectorPtr (var): the pointer you got from the create function
Function:
function clearGSVector(vectorPtr);
Description:
Clears the vector.
Parameters:
vectorPtr (var): the pointer you got from the create function
Function:
function pullOutOfGSVector(vectorPtr,pos);
Description:
Returns a value from the vector and erases it.
Parameters:
vectorPtr (var): the pointer you got from the create function
pos (int*): the position of the value
===============================================================
Example:
First of all you have to include the header file in your main.c:
After that declare some global vars for the vectors you'd like to
use so that you can use them from all of your scripts, for example:
Then create the vector objects you'd like to use for example in
your void main():
scheduler = createGSVector();
Now you can add values to the vector like this (scheduletask is a struct I use in my project):
SCHEDULETASK* scheduleTask = (SCHEDULETASK*)malloc(sizeof(SCHEDULETASK));
scheduleTask.timePoint = int_total_secs + 60;
scheduleTask.functionName = str_create("example schedule");
insertIntoGSVector(scheduler, scheduleTask);
You can add as many values as you like.
After that you can get back your stored values like this:
int tmpTime = 0;
int i = 0;
SCHEDULETASK* scheduleTask = (SCHEDULETASK*)malloc(sizeof(SCHEDULETASK));
while(1) {
tmpTime = int_total_secs;
if(levelReadyForPlaying != 0 && levelLoaded == 1 && cutsceneHandler == 0 && sizeOfGSVector(scheduler) > 0) {
for(i=0; i<sizeOfGSVector(scheduler); i++) {
scheduleTask = (SCHEDULETASK*)(getFromGSVector(scheduler,i));
if(tmpTime >= scheduleTask.timePoint) {
eraseFromGSVector(scheduler,i);
call_usefunction(scheduleTask.functionName);
}
}
}
wait(-1);
}
Of course you don't need to use a loop to get the values, you can access them directly by using "getFromGSVector" with the position of the value you want.
Attention: you have to use an "int*" value for the position ... don't store it in variable of type "var".
I hope this documentation helps a bit ... if there are some more questions or tips for improvement or even bugs ... just post them here or write me a PM.
Best regards,
Pegamode.