Page 2 of 2
Re: stick man sword

Posted:
Tue Oct 11, 2011 7:09 pm
by praaab
well when i set the variable: hit and try to press add imediate action then it will say error incorrect function usage: hit. Im not understanding why its an incorrect fuction
Re: stick man sword

Posted:
Tue Oct 11, 2011 8:24 pm
by skydereign
Well, is hit a variable or a function? I can't do much without seeing your game. But you might try changing the variable name to something else.
Re: stick man sword

Posted:
Tue Oct 11, 2011 8:31 pm
by praaab
Well wil hp-=1 work?
Re: stick man sword

Posted:
Tue Oct 11, 2011 8:58 pm
by skydereign
Oh, I get what you are doing. The hit(); should be replaced with your code. So, the hp-=1 bit. I thought you were talking about the attack variable that you need when using repeat collision.
Re: stick man sword

Posted:
Wed Oct 12, 2011 12:58 am
by praaab
No, let me repeat myself more clearly. When the enemy tries to hit me, i want to be able to bloc but right now im making the shield crappy and the blocking only works 50% of the time but u can block wenever u want it will just be half chance of getting hurt
Re: stick man sword

Posted:
Wed Oct 12, 2011 1:11 am
by skydereign
I know, and the explanations I have given are doing just that. The only problem is that if your game is going 30fps, and your enemies attack animation lasts for longer than 1/30th of a second, then if you set the collision event to repeat, then the enemy will pretty much be guaranteed to hit the player. For instance, if the attack only lasted one second, and your game runs at 30fps, then they have 30 attempts at hitting the player with a 50-50 chance. That means the chances of not getting hit are 1/1,073,741,824. I'm pretty sure that isn't what you meant by 50% chance of blocking. Therefore you need to limit the number of attempts to 1. You can do this by adding a variable that holds how many attempts are allowed, and whether the attempt succeeded or not, lower it.
So when the enemy attacks, set the variable to 1. When it collides with the player, check if it is greater than zero, and if so, try to hit the player. Regardless of the actual attack's result, lower the variable by 1 (normally to zero).
Re: stick man sword

Posted:
Wed Oct 12, 2011 1:46 am
by praaab
Alright well im reading a book about c++ and im very new to it and so im trying learn it and. Im not understanding how u would implement this piece of code in and how would i know if my game is running at 30fps
Re: stick man sword

Posted:
Wed Oct 12, 2011 3:23 am
by skydereign
If you don't know what fps your game is running, chances are high it is at 30 frames per second. You can change it by going to [Config] -> [Game Properties], and changing the frame rate.
Anyway, here's generally how you wold use it. Create an actor variable named attacking. Note though, if the player doesn't have an attacking, then you'll need to do it slightly differently where the variable is set to 1 on the collision.
enemy -> whatever event that causes it to attack (where the ChangeAnimation to the attack animation is) -> Script Editor
- Code: Select all
// presumably there are is at least a ChangeAnimation event here
attacking=1;
enemy -> Collision with player (repeat enabled) -> Script Editor
- Code: Select all
if(attacking==1 && (collide.animpos==7 || collide.animpos==8) && ((int)rand(2)==0))
{
hp-=1;
// and other code
}
attacking=0;
Re: stick man sword

Posted:
Wed Oct 12, 2011 8:46 pm
by praaab
this is becoming very frustrating, when i try to click ok after i right the code down i have two errors: 1: on line
1: Illegal structure operation
2: syntax error associated near '&&'
im so confused.
Re: stick man sword

Posted:
Wed Oct 12, 2011 9:03 pm
by skydereign
Sounds like you didn't upload your variables. Clearly this isn't working out, so can you upload your enemy and player animations, and I'll a ged with the code?
Re: stick man sword

Posted:
Wed Oct 12, 2011 9:29 pm
by praaab
well the problem is that i cant upload my game because it's over 2MB
Re: stick man sword

Posted:
Wed Oct 12, 2011 9:41 pm
by skydereign
Can you upload it to a file hosting site? If so, you can pm me the link. Though all I need for the example are those images.