SOLVED: boolean turns true and events happen if player walks on region.

Started by barefoot, Sun 08/05/2011 11:51:53

Previous topic - Next topic

barefoot

Hi

I am just getting into variables and have a bit of a problem implementing this one..

If main character has been manually scaled to12 by an inventory item and he then walks on a region a bool becomes true and events happen. Normally nothing will happen if he has not been Manually scaled.

I have made a variable bool in global pane and set name to hole and have it as false..

When player walks on to region I have this:

Code: ags

function region6_WalksOnto()
{
 if (cwizard2.Scaling==12)
 hole=true;
 SetTimer(1, 0);
 cwizard2.Transparency=100;
 cwizard2.Walk(842, 98, eBlock, eAnywhere);
 cwizard2.Transparency=0;
}


At the moment nothing happens.

If someone could help me out on this i would be grateful and will have learnt some more valuable knowledge.

cheers

barefoot




I May Not Be Perfect but I Have A Big Heart ..

barefoot

Hi

it seems i missed out a bit:

Code: ags


function region6_WalksOnto()
{
 if (cwizard2.Scaling==12)
 {
 hole=true;
 SetTimer(1, 0);
 cwizard2.Transparency=100;
 cwizard2.Walk(842, 98, eBlock, eAnywhere);
  cwizard2.Transparency=0;
 }
  else hole=false;
 }


Now it works, at least it appears to, I will test it some more!

barefoot



I May Not Be Perfect but I Have A Big Heart ..

NickyNyce

Hey barefoot,

I Barely know what i'm doing myself and have no business giving anyone instructions or help...but...if I'm not mistaken i don't think you need to put the (else hole=false;)
since the variable was false to begin with.

Sorry if I'm wrong.

barefoot

I May Not Be Perfect but I Have A Big Heart ..

Khris

Maybe I don't have enough info, but what is the point of the variable?
Are you checking it elsewhere?
Because in the code you posted, all you're doing is setting the variable. (It's like writing something on a Post-It, then never looking at it again.)

It seems to me like whether events are going to happen or not depends only on the scaling, so checking that should be enough.

barefoot

Hi Khris

its complicated.. sort of..  the player can walk onto a particular region under different guises like invisibility, morphing, levitating etc etc (can also be mixed) and only if the character has scaled down will that region's events happen.. he has to go through a rat hole... hence the scaling.

I think I still need to add a bit because I don't want events happening if he is also a  yeti!! (that's player scaled down and turned also into a yeti!") - I have now got this bit sewn up.

You obviously can't go into a rat hole if you're 6' tall...  :=

This is why I decided to use a variable bool...  it works and it was experience in using variables...still much to learn though.

I suppose I could of just used 'if player scaled' or 'else' instead.

Loved your post-it remark.

But its good that you pointed that out.

cheers

barefoot


I May Not Be Perfect but I Have A Big Heart ..

Khris

Hi barefoot.

I'm sorry, but let me put it this way: you haven't actually used the variable at all until there's a line in your code somewhere in which hole is part of an if condition. That's the point of using a boolean, at some point the game checks whether it's true or false.

So I'm afraid while what you wanted to do does work, it's not due to the variable and it also wasn't experience with using a variable since you left out actually using the variable.

I assume you're checking for the yeti form using player.View, another example where you don't need a variable but can read off the game state directly from available properties.

Some examples for bool usage:
1) the state of a light switch; in before fadein, the game sets up the room accordingly
2) a mouse movement flag; turn of inventory GUI if mouse not over it but mouse_was_above_GUI is true
3) player used a dialog option in another room and can now do something in the current room not available before (true indicates the player character learned something)

barefoot

Hi Khris

Yes, I can see what you mean, well put..  I had already stipulated if character is scaled... i did not need to add the bool..

If 2 conditions required I could have used: If Char Scaled && Char View

It's becoming much clearer.

Thanks Khris

barefoot


I May Not Be Perfect but I Have A Big Heart ..

SMF spam blocked by CleanTalk