How do I find the bottom of the Canvas?

Game Editor comments and discussion.

How do I find the bottom of the Canvas?

Postby EvanBlack » Sun Oct 02, 2011 1:58 am

I am trying to write a script that fills the canvas from bottom to top but I cannot figure out how to find the bottom of the canvas.

How do I get the height of the canvas? Or how do I set the pen to the bottom and increment -Y to draw lines left to right, bottom to top.
Last edited by EvanBlack on Sun Oct 02, 2011 10:54 pm, edited 2 times in total.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby skydereign » Sun Oct 02, 2011 2:00 am

If the canvas actor is the event actor (so you are drawing on it), you can use height. canvas coordinates are skewed, so (0,0) is the top left, and (width, height) is the bottom right.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby Game A Gogo » Sun Oct 02, 2011 2:03 am

sounds like you want to fill a canvas... though about using the erase function?
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby EvanBlack » Sun Oct 02, 2011 2:16 am

the height variable didn't do anything for me so I am not sure what you mean.

I tried setting a text actor to show the height of the canvas but it didn't change anything. Maybe my code is bugged. I am using the Script Reference like a bible and its just not complete enough. It doesn't explain the types of each variable nor does it seem to have all the possible variables for an actor. So its really confusing to try to "feel my way through the dark" when I am writing these scripts.

Yes. I am trying to fill a canvas. I don't like erase function so far it completely destroys my canvas. Maybe I used it wrong but I couldn't draw on my canvas after using it. Instead I just change the pen to a Transparent and draw over the canvas.


To explain what I am doing is I am trying to make a Health Bar. As the Health falls the canvas becomes less and less full. Then as the Health rises the Canvas becomes more full.

I would likes to use a percentage to figure the "fullness" of the health bar.

My idea is to use a canvas that draws lines up the canvas and sets it to full, maybe even saving this in the memory, then as the health depletes I set the pen to full transparent and start drawing transparent lines back down the canvas to show that it is emptying.

Problem is, I need an a for loop that knows the height of the canvas so I can set a percentage.

Here is the code I made that I think would do what I want but I get an error: Unexpected Declaration of setpen()

Code: Select all
setpen(0, 255, 0, 0.0, 3);
int i;
for(i = height; i >= 0; --i)
{
    moveto(i,0);
    lineto (i,width);
}
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby Game A Gogo » Sun Oct 02, 2011 2:44 am

int i; must be the first thing as variables must be the first thing declared in a script when you are declaring variables like that.

I dunno why erase doesn't work... it should work to fill completely the canvas S:
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby EvanBlack » Sun Oct 02, 2011 2:56 am

Ok. I didn't know that. Is that a script thing or a C thing? I always initialized variables where ever I wanted to use them. Thanks for that.

Also, I got the fill script to work by starting on a fresh FILE->NEW GAME. It fills it exactly like I wanted it to, I just don't understand why it wasn't filling in my other ged with the same exact script. Maybe I didn't get the pen to set properly. I will have to try again.

Well... I don't understand what is wrong with the first one I tried but the second one works perfectly even though they are exactly the same.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby skydereign » Sun Oct 02, 2011 4:10 am

So you know, the errors gE gives can usually tell you the type of the variable. I've never had the problem of not knowing what variable type things are, as it becomes apparent through the errors (if you were initially wrong). The script reference taught me pretty much everything there was to know starting out. Also, it does have all the built in actor variables (minus two obsolete ones).

Anyway (like Game A Gogo), I'm curious why you don't just use erase. As long as you draw after you erase, then it should work. So for instance, putting this in create, will set the canvas to red. You can then draw on it as you wish.
canvas -> Create Actor -> Script Editor
Code: Select all
erase(0, 255, 0, 0);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby EvanBlack » Sun Oct 02, 2011 5:45 am

Erase deleted my canvas.

I made a fill and the reason I want to use a loop is because its a health meter. Meaning it will fill in % depending on the health variable. It would have to be able to go up and down variably. Giving me half full, quarter empty, nearly full, 2% full.

I will post a demo of the variable health system once I have it finished so you can see it.


UPDATE:
So I got it but I have a new problem... it doesn't fill from bottom to top, instead its top to bottom...

Also, I get a permission denied to upload so I guess I can't show the demo...
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby lcl » Sun Oct 02, 2011 7:26 am

EvanBlack wrote:
Code: Select all
setpen(0, 255, 0, 0.0, 3);
int i;
for(i = height; i >= 0; --i)
{
    moveto(i,0);
    lineto (i,width);
}

There is two more errors in your code.
In moveto() and lineto() you should flip your values.
I mean the order you should input the values is moveto(x, y);
Currently you have x and y just in wrong places.

So, after fixing all the errors the code should seem like this:
Code: Select all
int i;

setpen(0, 255, 0, 0.0, 3);

for(i = height; i >= 0; --i)
{
    moveto(0, i);
    lineto (width, i);
}

But its exactly the same as:
Code: Select all
erase(0, 255, 0, 0);


But I guess what you're wanting to do is not just set the health bar green, but draw it green just to the point of you health. And maybe the missing health to be shown as red color.
Then, the code is here:
(This one is made supposing you wanted to make the healthbar vertical)
Code: Select all
int i, drawHere;

drawHere = height/maxHealth*health; //this gets the position to draw the health to.

erase(255, 0, 0, 0); //this makes the canvas be red, and now you can draw green on top of the red.
setpen(0, 255, 0, 0, 1);

for(i = 0; i < width; i ++)
{
    moveto(i, height);
    lineto (i, height-drawHere);
}

But in case you're wanting to make it horizontal, use this instead:
Code: Select all
int i, drawHere;

drawHere = width/maxHealth*health; //this gets the position to draw the health to.

erase(255, 0, 0, 0); //this makes the canvas be red, and now you can draw green on top of the red.
setpen(0, 255, 0, 0, 1);

for(i = 0; i < height; i ++)
{
    moveto(0, i);
    lineto (drawHere, i);
}


Hope this helped you! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby EvanBlack » Sun Oct 02, 2011 8:14 am

Thanks. I wish I saw this sooner. I figured it all out and but my method was a little different. I really should compare them... I have a working demo with poison and health up and health down now. This is the code I used, same thing.

Code: Select all
HealthBar->Timer

int i;
float hpPercent;

int i;

/*
//Clears the Canvas
setpen(255,0,0,1,3);
for(i = height; i >= 0; --i)
{
    moveto(i,0);
    lineto (i,width);
}
*/

erase(0, 0, 255, 1); //clears canvas with transparency

if(Poisoned){setpen(0,255,0,0,3);}
else{setpen(255,0,0,0,3);}

//Fills Canvas based on %
hpPercent = (float)PlayerHealth/(float)PlayerMaxHealth;
for(i =(int)((float)height*hpPercent); i >= 0; --i)
{
    moveto(0,width-i);
    lineto (height,width-i);
}




UPDATED
I compared the two in a side by side, in my demo. Your version doesn't fill the entire canvas, also if I extend the canvas to adjust it still doesn't fill right, if I make the length too long it over fills. Another problem with your Health bar... It doesn't support large numbers such as 6948. Really, HP should be a Float and not an Int but I am using Int's because they are easier to work with, even with the conversion here.

Try my code out for using the canvas but you can change the for loop to erase, I am sure its the same thing.

Maybe the two can be combined into one great looking one.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby lcl » Sun Oct 02, 2011 9:00 am

Please tell me now exactly what kind of healthbar you are making.
Is is horizontal or vertical?
Also tell what colours you are wanting to use and what is wrong with the results using my code.

Your code has x and y values in wrong places again, first comes X then Y, not oppositely.

I want to help you but I can't understand what you're trying to achieve.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby EvanBlack » Sun Oct 02, 2011 9:24 am

I already finished it. It works perfectly. Its like the Health Orb from Diablo. As your health drops the color drops. I already explained what was wrong with your code. It doesn't work.

There I got the demo to upload
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby lcl » Sun Oct 02, 2011 10:20 am

I tried my code and your code and mine worked (after I changed maxhealth and health to be floats), but yours didnt.
I tried your demo and it's funny how you have opposite results. :lol:

Glad you got it working anyway. :)

Btw, here's a hint for you.
Don't use timer for updating the healthbar, use
Draw actor -> script editor.
The event will be repeated all the time :)

You also seem to have written width when it would have to be height and oppositely in some cases. This doesn't have any effect to your code, since you've left the cavas actors as they are, with same height and width. But for future you should learn to use them right for avoiding strange issues. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: How do I find the bottom of the Canvas?

Postby EvanBlack » Sun Oct 02, 2011 7:43 pm

Alright thanks! I will have to change my code up XD

Just I can't seem to get good descriptions of what each function does and I keep getting more and more wanting to look at the source of GE but there are too many files for me. Or at least descriptions I can understand.

Yeah the Width/Height thing I know how it was suppose to be but I started out right but the problem was I wasn't getting the right results so I kept switching it around until I did. I knew my canvas was a square and thats why it was working but for some reason I kept getting strange results having them the right way.

My Game Editor is bugged I think... sometimes when I use the exact same scripts in a different ged the scripts are broken but work fine in others. Sometimes functions don't work but then I go back and try again after restarting GE and they work. I don't know if anyone else has this problem, its just a minor annoyance to me now that I know I can test if its my code or the game editor. I might have to re-download GE.

I have another question, OTHER THAN the documentation that comes with GE and using the search bar, is there ANYTHING that gives more better descriptions and tutorials on how to use ALL the functions of GE?

EDIT:
OMG!!! THANK YOU SO MUCH!!!

So Draw Actor is when the actor needs to be drawn to screen? OMG! I have been looking for that function and I wasn't sure to trust it, I thought it meant something completely different! Using this helped me find an fatal divide by zero error, I almost unraveled all of existence :lol:

About your code again, firstly, your also has a possible divide by zero error. Adding an: if(MaxHealth){... Health/MaxHealth ...} will make sure that if the Max Health is 0 then you wont get the error.

Also, even after changing the variables to floats I still couldn't get your code to work :? So I am wondering what is the difference.. How did you get yours to work?

EDIT:

I don't get it... These two are the same... Why doesn't the second one work.

Code: Select all
//Int Version, PlayerMaxHealth is an int
if(PlayerMaxHealthf){hpPercent = PlayerHealthf/(float)PlayerMaxHealth;}

//Float Version (This version doesn't work)
//if(PlayerMaxHealthf){hpPercent = PlayerHealthf/PlayerMaxHealthf;}
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest