Thoughts about data control

You must understand the Game Editor concepts, before post here.

Re: Thoughts about data control

Postby Fuzzy » Mon Oct 19, 2009 1:19 am

Ok Bee-Ant.

How do you do the shading on your art?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Mon Oct 19, 2009 3:43 am

Thats nothing todo with coding...but well, i will make a tutorial about it.
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Mon Oct 19, 2009 3:43 pm

Here's my shading tutorial using Ms. Paint
To the point, here's the description for each number of picture :


1. Draw an object and fill it with any color you want. The color is used as the original color in the shading later.

2. Pick any angle of light source. For example from the upper left. Then make at least 3 level of color. One is your original color, one is your brighter color of your original color, and one is your darker color of your original color. To do this, click your color pallete of the original color, click "Define Custom Colors >>" then scroll down or up the bar on the rightmost window to make the darker or brighter color. Fill the box's side that take the light directly with the brighter color, and fill the box's side that covered or doesnt take any light with the darker color. And leave the rest side with the original color.

3. That shading in number 2 is called "body shading". In picture 3, I add other kind of shading called "fall shading". This shading is formed on the surface under the object. The color of this shadow is decided by the original color of the surface under the box. In this case, I took white so the shadow is colored by grey. The tip angle of this shadow is decided by the angle of the light source.
Code: Select all
shadow_angle=light_angle+180;


4. Picture in number 4 is another sample of shading that use different angle of light source. I pick the upper right as the light source. Then the body shading and fall shading are drawn as in that picture. There're 3 kinds of shading: "body shading", "fall shading", and "reflection". The sample of reflection is that red ball in the picture 4. This stuff need color gradient to form the reflection. The color is fade to the color of the surface under the object.
Attachments
ShadingTutorial.png
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Tue Oct 20, 2009 1:02 am

Thanks. Thats quite interesting. And I think it counts as data control.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Tue Oct 20, 2009 4:08 pm

Here's more example on rounding surface :D
I'll come up with more advanced picture :P
Attachments
ShadingTutorial1.png
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Thoughts about data control

Postby DST » Wed Oct 21, 2009 3:36 am

I got some data control for you.

This is about the handshake rule - important when determining odds or possible combinations. The question goes like this:

If there are 6 people in a room, and they all shake hands, how many handshakes were there?

The answer is 15, because person one shakes hands with 5 other people, and person 2 shakes hands with 4, (he already shook hands with person 1), person 3 shakes 3, and so on.

So the handshake rule is simply 6=5+4+3+2+1. 15.

In gambling this is important for determining overall odds of games, especially when dealing with a deck of cards that doesn't reuse cards as it goes (blackjack). And so professional gamblers use card counting to beat the house. It also can be used to explain your odds in list gambling, such as the "NCAA Final Four' betting sheets that are popular in American workplaces.


Now there is an example from a few years ago where a child prodigy was discovered in a situation where the teacher asked the class to add up all the numbers from 0-100. While most kids took ten minutes to do it, one smart kid did it in 30 seconds. His solution was:

0+100=100;
1+99=100;
2+98=100;
and so forth until
49+51=100;
Of course, you'll have 50 of these combinations, so that's 5000,
leaving one 50, for a total of 5050. (the teacher wasn't using the pure handshake, as 100 was also intended to be used).

So this is why i tell you guys, please don't consider IQ tests as a measure of anything, if you do take one, don't rely on the results. You are as smart as your attitude+your hard work.

I think that child prodigy isn't smart at all, and i'll tell you why.

His method only worked for the number 100. I developed a method, when i was about 14 years old, that works for any number.

For this example, i'll use the top number too, as the teacher did.

If the number is even, its
Code: Select all
 (n-1) * (n/2) +n
For 6, that's 5*3=15+6=21. For 100, that's 99*50=4950+100=5050.

If the number is odd, its
Code: Select all
n * floor(n/2) +n
For 7, that's 7*3 = 21 + 7=28. For 101, that's 101 *50=5050 +101=5151.

I don't know why, i just know my method works. I found it out a stupid way, by simply testing answers till i found an equation that never seemed to be wrong. (i also worked out 2 to the 72nd power one day, power by power. I even fit it all on one piece of paper!) As you can see, i had better things to do in algebra class than listen to the teacher.

There are other variations on this method, they all pretty much do the same thing...just different order.

The only thing i can brag about with my method is that it doesn't leave you with floats, like the others do, and i add the final number on at the end, instead of inside, as many others do, so its simpler to convert my method to a pure handshake. On a computer, i guess it doesn't matter, but back in the days of pencil and paper, my method was a little easier.

But it doesn't really say anything about me, other than that i had a lot of free time on my hands. If i took an iq test, there's nothing to say that i wouldn't score lower than any of you. But a wise man once said to me, that i should never take an iq test. Why?

If you score 180, you will think you're smarter than everyone, and how hard will you work then? And if you only score 110, you'll think yourself dumb, and that might make you give up too. Its best to just let yourself learn at your own pace, and forget about what the world wants to measure about you.

Thus i say, life is the real test. Use wikipedia and use calculators. That is what REAL smart is.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby jimmynewguy » Wed Oct 21, 2009 7:30 pm

Woah....not jokeing here, i seriously just learned all about that this morning in algebra 2.....and his method does work for all #'s. I hate to say you must be out of practice because you did it wrong (kinda) it's supposed to start with
1+2+3+4...97+98+99+100
100+99+98+97...4+3+2+1
and so forth and they all = 101 you do this 100 times so 101*100=10100 but since really you did that twice divide be 2 and you get 5050(but you did get the right answer). But he didn't come up with the actual formula, just the idea. the forumula is
1/2(n(n+1)). 1/2(100*101) = 5050 :) sorry im not the best at explaining things, it's easier to talk it out then it is to type it lol
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Thoughts about data control

Postby DST » Wed Oct 21, 2009 7:57 pm

LOL! One thing that helps is that we all code, and can use code notation instead of traditional algebra.

One thing i hate about traditional notation is stacking equations (when dealing with fractions or division). I also don't like the way that it has no basis in reality. I never paid attention in algebra or calculus because i had no need for it.....i couldn't make games when i was in high school. (I was a freshman in 1990...the school had just gotten pcs' running windows 3.1 that very year.)

The only programming class they offered there was pascal, and pascal 3.1 at that (pascal was on 5 then). Like i said, i didn't go to a very good school.

And i think my equation is just fine jimmy! LOL Like i said, my version didn't leave floats or return huge numbers; calculating 99 is simply floor(99/2). Well, you don't need a calculator to know the answer is 49. And then its just 49x99. Now in the equation you give, the number gets inflated to 10100, which is much larger number than is needed.

Remember, i had to use pencil and paper. Keeping it simple was uber-important. Also, the inclusive method (which is what i find most commonly on google) isn't as useful, because most of the applications of this will start with the first number already on the table, so the final number shouldn't be part of the solution. (For instance, if you're counting cards, you can't say anything about the deck until one card is dealt, but at that point, that card is no longer in the deck and no longer part of the equation). Thus what i said about true handshake vs. inclusive handshake.


Though it means i will become obsolete, i'm glad that our society is making leaps like it is. When you guys are my age, you're going to be 100x better at all of this stuff than i am now. The future humans will look back on us with pity, that we had to type into our computers and learn stuff the hard way, just as i feel sorry for the people of the past...before computers and machines, they couldn't automate anything....Imagine, when you wanted something to happen more than once, you actually had to do it more than once!

Imagine making a great painting, but not being able to copy it or back it up...you'd just have to watch it decay over the years.

We are truly fortunate to have all this. Computers, scripts, GNU, Google, GE Forum.....we are lucky!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Tue Oct 27, 2009 11:17 am

Suppose that there is a programmer.

This programmer has written a function that generates enemies, of which there are two types, green and blue.

His function generates two enemies. The enemies do not immediately show up in the view. What are the chances that at least one of enemies are green?

What we have to do is calculate the solution space. This is a list of all possible outcomes.

In this example we have
[blue,blue],[blue,green],[green,blue],[green,green]

Since we dont know the order of the generation, we have both [blue,green] and [green,blue] as possibilities.

Now all we have to do is add up the number of greens. In 3 possible outcomes, green is possible. So thats 3/4 or 75% chance that at least one is green.

Now what happens if we know we have a green enemy? What are the chances of the other enemy also being green?

You might be tempted to say 50/50, but it isnt so. We havent said if the first or second enemy was green, and that makes all the difference.

Now we have the same solution space, but we have to drop [blue,blue] as it isnt possible.In fact, the only favourable outcome is [green,green] and that is one of three (1/3) or 33.333% chance that both are green.

Isnt that odd? if we know the type of the first generated enemy, then the type of the second is 50/50, but if we dont know the order, then its only 33/100.

I brought this up because nobody ever discusses random when it comes to data control, but you can see that it is possible to approach even random numbers with logic.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby DST » Sat Dec 19, 2009 10:00 am

using loops more effectively

When using a loop to fill in a 1 dimensional array, you could do it like this:
Code: Select all
int i;
int j;
int k;
for(i=0; i<300; i++){
CreateActor("puzzlepiece", "puz", "(none)", "(none)" , k*32, j*32, true);
j++;
if(j==20){
j=0;
k++;
}
}


Or you could use modulo:
Code: Select all
int i;
int j;
int k;
for(i=0; i<300; i++){
j=i%20;
k=(i-j)/20;
CreateActor("puzzlepiece", "puz", "(none)", "(none)" , k*32, j*32, true);
}


you can use loops to create lookup tables for variables instead of calculating them on the fly;
in this case, the xy coordinates of your cells
Code: Select all
int mapCells[300][2]; //this would go in global script
assigncells(32, 20); //32px cells, 20 in each row

void assigncells(int size, int hcells){ 
int i;
int j;
for(i=0; i<300; i++){
j=i%hcells;                   /*if i is 25, the remainder of i/20 is 5 that's the column, 25-5=20/20=1 that's the row....*/
k=(i-j)/hcells;
mapCells[i][0]=j*size;  //storing x coordinate
mapCells[i][1]=k*size;  //storing y coordinate
}
}


then when you say, swap puzzle pieces, a piece has determined it must move into the cell to the right of it, then you just say

Code: Select all
moveto("Event Actor", mapCells[mycell+1][0], mapCells[mycell+1][1], "", "", 4);


Lookup tables can save cpu, if that is your bottleneck. All depends on what you need most.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Sat Dec 19, 2009 4:42 pm

Bubble sort using loops and array
Code: Select all
void Sort()
{
   for(int i=0;i<999;i++)
   {
      for(int j=0;j<arraysize-1;j++)
      {
         int temp;
         if(array[j+1]>array[j])
          {
            temp=array[j];
            array[j]=array[j+1];
            array[j+1]=temp;
         }
      }
   }
}
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Sat Dec 19, 2009 10:32 pm

DST wrote:then when you say, swap puzzle pieces, a piece has determined it must move into the cell to the right of it, then you just say

Code: Select all
moveto("Event Actor", mapCells[mycell+1][0], mapCells[mycell+1][1], "", "", 4);




Good one DST.

Dont forget that if you always move using variable mapCells that you can define that in global code.
Code: Select all
#define RIGHT mapCells[mycell+1][0]
#define LEFT mapCells[mycell-1][0]

and so on. Dont use a ; to end the lines.

Then use it..

Code: Select all
moveto("Event Actor",RIGHT, RDOWN, "", "", 4);


Note that if I had typed

Code: Select all
moveto("Event Actor",RIGHT, RIGHTDOWN, "", "", 4);


GE would see the line of code as this, creating an error.

Code: Select all
moveto("Event Actor", mapCells[mycell+1][0], mapCells[mycell+1][0]mapCells[mycell+1][1], "", "", 4);


So be very careful of what names you use. It will replace any instance of those characters with the code from the define. It is case sensitive too, so thats why we tend to use all capitals in #define.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Fuzzy » Sat Dec 19, 2009 10:56 pm

Bee-Ant wrote:Bubble sort using loops and array
Code: Select all
void Sort()
{
   for(int i=0;i<999;i++)
   {
      for(int j=0;j<arraysize-1;j++)
      {
         int temp;
         if(array[j+1]>array[j])
          {
            temp=array[j];
            array[j]=array[j+1];
            array[j+1]=temp;
         }
      }
   }
}


Its good to finally see someone getting into sort functions. Know any others?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Thoughts about data control

Postby Bee-Ant » Sun Dec 20, 2009 9:49 am

what do you want?
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Thoughts about data control

Postby DST » Sun May 30, 2010 5:34 am

Assumptions are dangerous in programming.

One of the common issues new users have is variables not being what they expect them to be, for instance, if you have two mousepress events with mouseup events, and you hold left, press right, release left, release right, the 'mouseup>left' event does not occur. Moonwalking is often related to this type of 'assumption'.

The most sensible way to snap values is to reset them every frame. Don't assume the player is still holding or not holding a button. Tell the game that the button is no longer held down at the beginning of each draw actor, then change the appropriate variables if you detect it to be held down again, then run your script.

If you are using the keydown events, you can instead reset them at the end of draw actor. Here's the sequence:

1. Keydown>left>
dir=1;
2. draw actor>
if(dir==1){
}
dir=0;
3. frame renders
1. keydown>left>
dir=1;
2. draw actor>

etc. etc.

In case you're wondering why you'd need to do things like this if ge has a builtin keydown event, the reason is that Input Events are handled initially by your OS, not ge.

If you cannot duck and move left at the same time, and the user is pressing both keys, which event occurs first, arrowleft or arrowdown? After dealing with programming input in raw code, i can assure you, there IS an order. Any platform you work in has a definite order of key reads, and this can cause you frustration to no end, because if you hold down all four, the last key read will be the final ouput, overriding the others(if they produce conflicting code, which with events like ducking, they often do). Ge is actually pretty good at handling this, but it applies to many other variables besides key events.

Assume everything is 0 again, and force the script to prove the variable is 1 before working with that variable. It will save you lots of errors and save you from ending up with lots of 'abandoned' games.


The same thing applies to many other types of variable. Consider how easily you could write your own mousebuttondown script; Check this out.

FilledRegion>MouseButtonDown> //filled region to catch all mouse clicks
Code: Select all
mx=0;    //reset variable to 0
gx=xmouse;   //store mouse coords
gy=ymouse;
mx=1;            //indicate mouse was clicked


Button>Draw Actor
Code: Select all
if(mx==1){      //if mouse has been pressed
if(abs(gx-x)<width/2 && abs(gy-y)<height/2){ //and mouse position is less than 1/2 width and height from actor center
//do mousebuttondownscripthere;         //then i am the button that was clicked on.
mx-0;             //click was recieved, so deactivate it. Force the variable back to 0.
}
}


or

FilledRegion>MouseButtonDown> //filled region to catch all mouse clicks
Code: Select all
DestroyActor("mxtest");
CreateActor("mxtest", "dot", "no_parent", "no_path", xmouse, ymouse, true);


Button>Collision>mxtest>
Code: Select all
//domousebuttondownstuffhere;
DestroyActor("Collide Actor");


In the second example, the actor 'mxtest' is simply holding the xmouse/ymouse coords just as our global variables gx and gy were doing before, and the collision is replacing the abs(x-mx) test part, while the destroy collide actor replaces the line mx=0;

If no button is under the mouse, it's okay, because the filled region reset mx/destroyed mx test at the beginning of the mouseclick anyway. This is what i am talking about.

Now these mouseclick methods aren't particularly useful, but it shows how by forcing variables back to 0, you can better predict what will happen.

EAPF
The programmer's motto:
it's Easier to Ask for Permission than Forgiveness.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

PreviousNext

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest