Page 1 of 1

[SOLVED]QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 4:28 pm
by DragonRift
I want to do a Procedural Quad Tree and I am not sure where to start on the engine itself. Anyone have any advice?

http://en.wikipedia.org/wiki/Quadtree

The goal is to design procedural worlds and have them in sections of my GED, treating each as a level using Activation Areas.

Edit: I think I am going to have to do the work in Global Code.

Re: QuadTree

PostPosted: Thu May 16, 2013 6:40 pm
by skydereign
Yes, you will most definitely need to create the data structure in global code. Have you ever made a data structure before? Do you know how pointers work in C? If so, just following the pseudocode should be sufficient. If not, you should learn the basics of pointers and functions first.

Re: QuadTree

PostPosted: Thu May 16, 2013 6:56 pm
by DragonRift
skydereign wrote:Yes, you will most definitely need to create the data structure in global code. Have you ever made a data structure before? Do you know how pointers work in C? If so, just following the pseudocode should be sufficient. If not, you should learn the basics of pointers and functions first.


I decided to hold off on the QuadTree for a bit but one thing I am stuck on is how to update a Text based actor to information that is controlled by a variable. :roll:

Essentially, I want to have a Variable in an actor's text.

Global Script:
Code: Select all
int RPointVar = 0;

void RPTimer()
{
 CreateTimer("RPVar", "RPTick", 300);
 RPointVar+=1;
}



Then I have a Text Actor called RPVar with a default text that says 0.

I want to make it take the value of RPointVar.

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 7:14 pm
by skydereign
text is a string (represented by a char*). Therefore you can use the function sprintf to set text. http://www.cplusplus.com/reference/cstdio/sprintf/

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 7:21 pm
by DragonRift
skydereign wrote:text is a string (represented by a char*). Therefore you can use the function sprintf to set text. http://www.cplusplus.com/reference/cstdio/sprintf/


The issue is not with the variable but with the fact that I want to have the Actor.text be controlled by code, and I cannot find any docs that say how to do this

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 7:25 pm
by skydereign
DragonRift wrote:The issue is not with the variable but with the fact that I want to have the Actor.text be controlled by code.

Right... and that is what sprintf allows you to do. The reason I mentioned it was a char* is that that would help you search more about them, as there are more than the one function I mentioned. One thing you might not realize, nothing in gE happens automatically. Every thing in your game needs to have code causing it. Therefore, if you wanted a text actor to display your variable every frame, you need code to set it every frame (for instance in a draw actor event). And the best way to set text of an actor is to use sprintf.
hp_text -> Draw Actor -> Script Editor
Code: Select all
sprintf(text, "hp: %d", hp);

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 7:28 pm
by DragonRift
skydereign wrote:
DragonRift wrote:The issue is not with the variable but with the fact that I want to have the Actor.text be controlled by code.

Right... and that is what sprintf allows you to do. The reason I mentioned it was a char* is that that would help you search more about them, as there are more than the one function I mentioned. One thing you might not realize, nothing in gE happens automatically. Every thing in your game needs to have code causing it. Therefore, if you wanted a text actor to display your variable every frame, you need code to set it every frame. And the best way to set text of an actor is to use sprintf.
hp_text -> Draw Actor -> Script Editor
Code: Select all
sprintf(text, "hp: %d", hp);


I am confused because its not letting me put any Variables in the TEXT WINDOW to be controlled. Sorry, I am new to programming and this is all hard for me currently.

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 7:33 pm
by skydereign
DragonRift wrote:I am confused because its not letting me put any Variables in the TEXT WINDOW to be controlled.

Right, because you can't do that. You need to set text with code if you want it to display the value of a variable. As I said, nothing happens automatically. That example I showed will set the hp_text actor's text to display hp, if you just want to display an int, it can be easily changed to display your variable.

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 7:44 pm
by DragonRift
skydereign wrote:
DragonRift wrote:I am confused because its not letting me put any Variables in the TEXT WINDOW to be controlled.

Right, because you can't do that. You need to set text with code if you want it to display the value of a variable. As I said, nothing happens automatically. That example I showed will set the hp_text actor's text to display hp, if you just want to display an int, it can be easily changed to display your variable.


OK, here is what I have:

Global Script:
Code: Select all
int RPointVar = 0;

void RPTimer()
{
 CreateTimer("RPVar", "RPTick", 300);
 RPointVar+=1;
}


Actor Script:
Code: Select all
sprintf(text, "Research Points: %d", RPointVar);


Actor Text:
Code: Select all
Research Points: 0


Its loading the variable but the timer is not working now.

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 8:05 pm
by skydereign
That's because nothing happens automatically. It looks like you are assuming the function you declared is automatically running. This is not the case. You need to run that function for it to increase your variable.

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 8:10 pm
by DragonRift
skydereign wrote:That's because nothing happens automatically. It looks like you are assuming the function you declared is automatically running. This is not the case. You need to run that function for it to increase your variable.


Can you show me a inline forum code example of the timer activating the code that needs to rely on the timer?

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 8:17 pm
by skydereign
Note, the create actor event runs the function once, which will create the timer. Then the timer event will call the function again, creating another timer. That repeats.
RPVar -> Create Actor -> Script Editor
Code: Select all
RPTimer();

RPVar -> Timer (RPTick) -> Script Editor
Code: Select all
RPTimer();


Now, you could do the same thing with the following code (if you make the timer RPTick set run infinitely).
RPVar -> Create Actor -> Script Editor
Code: Select all
CreateTimer("Event Actor", "RPTick, 300");

RPVar -> Timer (RPTick) -> Script Editor
Code: Select all
RPointVar++;

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 8:25 pm
by DragonRift
skydereign wrote:Note, the create actor event runs the function once, which will create the timer. Then the timer event will call the function again, creating another timer. That repeats.
RPVar -> Create Actor -> Script Editor
Code: Select all
RPTimer();

RPVar -> Timer (RPTick) -> Script Editor
Code: Select all
RPTimer();


Now, you could do the same thing with the following code (if you make the timer RPTick set run infinitely).
RPVar -> Create Actor -> Script Editor
Code: Select all
CreateTimer("Event Actor", "RPTick, 300");

RPVar -> Timer (RPTick) -> Script Editor
Code: Select all
RPointVar++;



THis is presuming that my timer is an actor, I have created my timer in global code and I want it to incrementally increase from script without creating an additional actor.

I have:

GLobal Code:
Code: Select all
int RPointVar = 10;

void RPTimer()
{
 CreateTimer("RPVar", "RPTick", 5000);
 
}


Actor Script:
Code: Select all
sprintf(text, "Research Points: %d", RPointVar);

RPTimer();
{
  RPointVar+=1;
}


In my Text Actor's Script yet its still increases at 1 point per MS, and I do not have the Timer showing up as an option when I try and create timer in the way that you are saying.

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 8:30 pm
by skydereign
Timers are not actors, but they are entities that belong to actors. Since all code in gE must be run from an actor, a timer is created for a given actor, and that will eventually trigger that actor's timer event. This is very similar to the idea that all code must be run. To reiterate, functions in global code must still be run within an actor event. Timers belong to actors, and cannot be used in any other way.

Re: QuadTree, Variables, Data Storage/Recovery

PostPosted: Thu May 16, 2013 8:38 pm
by DragonRift
skydereign wrote:Timers are not actors, but they are entities that belong to actors. Since all code in gE must be run from an actor, a timer is created for a given actor, and that will eventually trigger that actor's timer event. This is very similar to the idea that all code must be run. To reiterate, functions in global code must still be run within an actor event. Timers belong to actors, and cannot be used in any other way.


I appreciate your help, this is solved.