[SOLVED]QuadTree, Variables, Data Storage/Recovery

Game Editor comments and discussion.

[SOLVED]QuadTree, Variables, Data Storage/Recovery

Postby DragonRift » Thu May 16, 2013 4:28 pm

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.
Last edited by DragonRift on Thu May 16, 2013 8:41 pm, edited 2 times in total.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: QuadTree

Postby skydereign » Thu May 16, 2013 6:40 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: QuadTree

Postby DragonRift » Thu May 16, 2013 6:56 pm

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.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby skydereign » Thu May 16, 2013 7:14 pm

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/
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby DragonRift » Thu May 16, 2013 7:21 pm

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
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby skydereign » Thu May 16, 2013 7:25 pm

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);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby DragonRift » Thu May 16, 2013 7:28 pm

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.
Last edited by DragonRift on Thu May 16, 2013 7:34 pm, edited 1 time in total.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby skydereign » Thu May 16, 2013 7:33 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby DragonRift » Thu May 16, 2013 7:44 pm

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.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby skydereign » Thu May 16, 2013 8:05 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby DragonRift » Thu May 16, 2013 8:10 pm

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?
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby skydereign » Thu May 16, 2013 8:17 pm

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++;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby DragonRift » Thu May 16, 2013 8:25 pm

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.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby skydereign » Thu May 16, 2013 8:30 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: QuadTree, Variables, Data Storage/Recovery

Postby DragonRift » Thu May 16, 2013 8:38 pm

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.
DragonRift
 
Posts: 70
Joined: Mon May 13, 2013 5:05 am
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest