Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, TipmyPip, VoroneTZ, Quad, 1 invisible), 688 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 4
Page 2 of 6 1 2 3 4 5 6
Re: GSVector [Re: pegamode] #256113
03/14/09 18:08
03/14/09 18:08
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
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:

Code:
#include "GSVector.h"


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:

Code:
var scheduler;


Then create the vector objects you'd like to use for example in
your void main():

Code:
scheduler = createGSVector();


Now you can add values to the vector like this (scheduletask is a struct I use in my project):

Code:
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:

Code:
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.


Last edited by pegamode; 03/14/09 19:19.
Re: GSVector [Re: pegamode] #256124
03/14/09 18:29
03/14/09 18:29
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline
Member
KDuke  Offline
Member
K

Joined: Mar 2009
Posts: 112
Germany
Thank you very much for the documentation and the code examples.

Though I gotta mention one thing about the position variable!
It not only has to be of type int it HAS to be int*

EDIT: please mention that in the documentation!

Last edited by KDuke; 03/14/09 18:30.

Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: GSVector [Re: KDuke] #256131
03/14/09 19:15
03/14/09 19:15
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
You're absolutely right.

Here's a more simple example:

Code:
var testVec = createGSVector();
insertIntoGSVector(testVec,1);
insertIntoGSVector(testVec,2);
insertIntoGSVector(testVec,3);
insertIntoGSVector(testVec,4);
	
int* pos = 2;
var check = getFromGSVector(testVec, pos);
diag("GSVectorCheck: ");
diag(str_for_num(NULL, check));



Regards,
Pegamode

Re: GSVector [Re: pegamode] #256561
03/17/09 15:16
03/17/09 15:16
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
The documentation is now included in the download.

Re: GSVector [Re: pegamode] #261049
04/15/09 13:22
04/15/09 13:22
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
i got idea... add function, that add unique value to vector.
For example,
function insertIntoGSVectorUnique(vectorPtr,value);

this can check, if values isnt inside vector, then add (runs throung all elements and check)

i'd write this function by my own in lite-c, but i'd wait until you add it, as it supose to be faster


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: GSVector [Re: VeT] #261058
04/15/09 13:50
04/15/09 13:50
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
what a...

Code:
typedef struct { 
  var s;
  var i;
  var j;
  
  var step_max;
  var step_left;
  
} CHARACTER;

******

	vPlayers = createGSVector();
	CHARACTER* tempChar;
	
	tempChar.s = file_var_read(fhandle);
	tempChar.i = file_var_read(fhandle);
	tempChar.j = file_var_read(fhandle);
	
	tempChar.step_max = file_var_read(fhandle);
	tempChar.step_left = file_var_read(fhandle);
	
	insertIntoGSVector(vPlayers,tempChar);


i got a crash frown


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: GSVector [Re: VeT] #261059
04/15/09 13:52
04/15/09 13:52
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
ah.. i needed
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));

i thought, Lite-c works automatically for pointers

PS: i decided not to delete this post, as it can helps another people


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: GSVector [Re: VeT] #261064
04/15/09 14:07
04/15/09 14:07
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
okay, next step...

Code:
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));

very_very_temp = sizeOfGSVector(vPlayers); // debug shows size = 1, thats right


for(i=0; i<sizeOfGSVector(vPlayers); i++) {
tempChar = (CHARACTER*)(getFromGSVector(vPlayers,i));
		
very_very_temp = tempChar.s; // now its 0, but may be 1, as in file written
very_very_temp = tempChar.i;// this is also 0, may be 2
very_very_temp = tempChar.j;// 0, may be 3



1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: GSVector [Re: VeT] #261067
04/15/09 14:38
04/15/09 14:38
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
1) some errors detected in eraseFromGSVector (as i have 2 components in vector, use second and then erase it, when i run through vector, only second(not first) component is inside)

2) i have a trouble with analog of yours
scheduleTask = (SCHEDULETASK*)(getFromGSVector(scheduler,i));
function craches when i run second loop (looking like we need to remove scheduleTask after first loop)


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: GSVector [Re: VeT] #261161
04/16/09 06:13
04/16/09 06:13
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Hi VeT,

could you please post the whole code you use?
It's hard to analyze your code snippets as they are not working standalone
to see what's happening in the code you run.

Regards,
Pegamode.

Page 2 of 6 1 2 3 4 5 6

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1