Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 946 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 4
Page 3 of 6 1 2 3 4 5 6
Re: GSVector [Re: pegamode] #261180
04/16/09 08:19
04/16/09 08:19
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 was starting to write code, but i got idea how to fix that problem smile
code is in office, and now i'm at home... in some hours i'd be there and, is problem still exist, i'd post it here

Thanks for fast answer smile


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] #261233
04/16/09 13:50
04/16/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
Okay, here i am...
As i see, post is long, so please, read carefully, its not hard smile

So, i have a struct
Code:
typedef struct { 
  var s;
  var i;
  var j;
  
  var step_max;
  var step_left;
  
} CHARACTER;


Then, i have a text file, where info about CHARACTERs is stored..
For example, i have info about 2 characters:
first with s=1; i=4; j=2;,
second one with s=1; i=5; j=5;

But, as character model are not created immideately, i need to store that info in vector. So i read my file:
Code:
players_number = file_var_read(fhandle);

vPlayers = createGSVector();
CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
	
var i;
for (i=0; i<players_number; i++)
{
	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);
}


On this step everything looking okay, and debugger shows that vector vPlayers consist of 2 elements, thats right

Next, i create 2 players models (first, in coordinate s=1; i=4; j=2; , second - in s=1; i=5; j=5;) and i want to load info about their step_left from vector

So, i add function
Code:
void GetPlayerInfo(var s,var i, var j)
{
	ENTITY* tempEnt;
	int num;
	
	CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
	
	while(sizeOfGSVector(vPlayers)==0) {wait(1);}
	very_very_temp = sizeOfGSVector(vPlayers);
	wait(1);	
	
	for(num=0; num<sizeOfGSVector(vPlayers); num++) {
		very_very_temp = num;
		tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));	
		
		if ((tempChar.s == s) && (tempChar.i == i) && (tempChar.j == j))
		{
			tempEnt = ReturnModelPointer (TypeModel,s,i,j);
			
			tempEnt.sPlayerStepsMax = tempChar.step_max;
			tempEnt.sPlayerStepsLeft = tempChar.step_left;
			
			very_very_temp = tempEnt.sPlayerStepsLeft;
			
		//	eraseFromGSVector(vPlayers,num);
			tempChar = NULL;
			break;
		}
		tempChar = NULL;		
	}
}


In this function i go through vector, take elements one-by-one and compare element's s,i,j with models s,i,j.
If true, then i load step_max to entity's skill, if not, i'm proceeding to next element.

Now, the problem:
If i have first entity with coordinates 1,5,5, and first element of vector has 1,5,5, then everything works okay.
BUT, if i compare first entity's 1,4,2 with first element with 1,5,5, then i come to the second vector's element (1,4,2) and in string
Code:
tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));

i got a crash

I tried to say it as simple as possible smile


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] #261236
04/16/09 13:58
04/16/09 13:58
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
some additional tests shows, that trouble right in
getFromGSVector(vPlayers,num);

i'd look deeply here


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: KDuke] #261245
04/16/09 14:18
04/16/09 14:18
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Originally Posted By: KDuke
Hm...

now that I'm finally at the point to actually implement GSVector I'm at loss.
Although I've been using Vectors in C++ before I can't get this one running.

A documentation is really needed.

I already managed to insert several values though I only can use
Code:
getFromGSVector(myVector, 0);

As soon as I use another position the engine crashes.

greetings
KDuke


mmm... yes, something like this.. int* crashes for me, looking like i need work with it


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] #261246
04/16/09 14:33
04/16/09 14:33
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Code:
	int num;
	
	for(num=0; num<sizeOfGSVector(vPlayers); num++) {
		int* pnum;
		pnum = num;
		very_very_temp = pnum;
		wait(1);
		tempChar = (CHARACTER*)(getFromGSVector(vPlayers,pnum));


at least this not crash smile
damned this half-automatically pointer recognition ability of the engine... mad smile


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] #261298
04/16/09 19:56
04/16/09 19:56
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,

using a code similiar to this:

Code:
for(i=0; i<sizeOfGSVector(scheduler); i++) {
    scheduleTask = (SCHEDULETASK*)(getFromGSVector(scheduler,i));
}


works fine in several projects of mine.
Just when I directly access a position in the vector I need to use an int* as it is described in the documentation.

But are you sure to store your values like that in a vector?
In worst case you have to run through the whole vector to get back your values.

Wouldn't it be better to store your struct in a hashmap and then access it directly with a unique key?

In my current projekt (point&click adventure) I have hundreds of useable objects and each of them has additional data stored in structs ... I store those structs in a hashmap and as a key I use a unique ID that is written in string1 of the entity. So if I have the entity I can directly access all additional data by using the ID to get the struct out of the hashmap.

Regards,
Pegamode.

Re: GSVector [Re: pegamode] #261305
04/16/09 20:35
04/16/09 20:35
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
//using a code similiar to this:
In your case, i is integer or var?

You see, i save all info about land parts (name of model and angle) and models (name of model, angle and HP) in different matrixes in *.lvl file (just text file). Really, i'm able to add matrix with steps_max, steps_current, types of weapons and so on... but its looking like better to save info about charackers in strings after matrixes.


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] #261351
04/17/09 05:59
04/17/09 05:59
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
In my case i is an int ...

To store additional info for models I use some kind of csv-file.
Each line contains a referenceID to the model and about 30 additional data for each model.
I read those data into struct objects and store those objects in a hashmap using the referenceID as key.
So I can directly access those struct objects for each model. I can even store states like "door is open" during the whole game. So when I leave the room and load the next and then come back later to the same room, the door is still open.

Re: GSVector [Re: pegamode] #261370
04/17/09 08:41
04/17/09 08:41
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Hm.. so, you read/write text from file dynamically?
F.e, you read door statement, then player change it, and you write it in a file again?

I chose another way: i read one time info about models from matrixes and store(and change) it there.. while level saved, i save matrixes into file one time.

But between reading info and creating models i need to store info about players somewhere else, like in your vector.


//In my case i is an int ...
But what about KDuce's note
Quote:

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!



I tried this way:
Code:
void GetPlayerInfo(var s,var i, var j)
{	
	CHARACTER* tempChar = (CHARACTER*)malloc(sizeof(CHARACTER));
	while(sizeOfGSVector(vPlayers)==0) {wait(1);}
	diag("\n[!!!] Vector size:");
	diag_var(" size: %6.3f",sizeOfGSVector(vPlayers));
	
	int num;	
	for(num=0; num<sizeOfGSVector(vPlayers); num++) {
		tempChar = (CHARACTER*)(getFromGSVector(vPlayers,num));
		
		diag("\n[!!!] Vector:");
		diag_var(" s: %6.3f",tempChar.s);
		diag_var(" i: %6.3f",tempChar.i);
		diag_var(" j: %6.3f",tempChar.j);
	}
}

and this gives me

[!!!] Vector size: size: 2.000
[!!!] Vector: s: 1.000 i: 5.000 j: 5.000
Error E1513: Crash in GetPlayerInfo
Program aborted

Now, if i change order of storing values in vector, it returns
[!!!] Vector size: size: 2.000
[!!!] Vector: s: 1.000 i: 4.000 j: 2.000
Error E1513: Crash in GetPlayerInfo
Program aborted


So, from all this i can say that insertIntoGSVector works fine, but i may deal with getFromGSVector

Please, can you gibe more info about getting values from vector?


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] #261377
04/17/09 09:31
04/17/09 09:31
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline
Member
KDuke  Offline
Member
K

Joined: Mar 2009
Posts: 112
Germany
Hi VeT!

In the meantime I've encountered problems with simply using int* as well.
I had the same trouble as you have. Tried different things until I came (I think at least so, I don't have my source at hand right now) to a point where I noticed that it is working when I use a global int for the getFromGSVector index.
If you try to use a local variable getFromGSVector it needs to be of datatype byte* because if you use
Code:
int* example = 0;
example ++;

the value of example will be 4 as an int is 4 bytes big and therefore the pointer is increased in multitudes of four. Thats how it is working for me right now. But maybe pegamode just should check his source for getFromGSVector. It indeed behaves strange in some situations.

greetings
K-Duke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Page 3 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