Posted: Mon Nov 02, 2009 12:36 am Post subject: Procedures?!?!?!?!
What is it you are trying to achieve?
I am trying to make an rpg with a constantly moving enemy, as well as being able to move and attack.
What is the problem you are having?
I need to know how to make it so that the enemy moves off to the side constantly while the main procedure is working at the same time. (e.g. I want to be able to move and attack at the same time as the enemy moving)
Describe what you have tried to solve this problem
i have created a procedure and even tried getting rid of it but im not sure what to do.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:
<procedure EnemyRobot
Sprite.SetPosition(enemyrobot, robotx, roboty, false) Sprite.Show(enemyrobot) for n :1.. Enemy_robot
Sprite.Animate(enemyrobot, Enemyrobot ((n div1)mod Enemy_robot + 1), robotx, roboty, false) delay(50) endfor end EnemyRobot>
Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
Tony
Posted: Mon Nov 02, 2009 1:15 am Post subject: Re: Procedures?!?!?!?!
Chaoskiller @ Mon Nov 02, 2009 12:36 am wrote:
... at the same time as ...
In procedural programming, there is no such thing as "at the same time". One thing happens, then another thing happens. If both of those things happen fast enough, then it might seem as if they are happening together.
code:
loop
move_player()
move_enemy()
delay() % this is the only delay you should have in your program
end loop
Posted: Mon Nov 02, 2009 8:04 am Post subject: RE:Procedures?!?!?!?!
Just out of curiosity, what's the point of dividing an integer by 1?
Chaoskiller
Posted: Mon Nov 02, 2009 9:56 am Post subject: Re: RE:Procedures?!?!?!?!
Euphoracle @ Mon Nov 02, 2009 8:04 am wrote:
Just out of curiosity, what's the point of dividing an integer by 1?
I'm not too sure, I dont undertsand everything all i know is it doesnt work without that. Also i think it means that you are dividing the "for" by 1 if i was to make it div 8 the frames would appear faster and skip a lot.
Tony how is it possible to make 2 things happen at once then?
I need a delay in my animation in order for it to look normal so i cant make them happen as fast as possible.
Superskull85
Posted: Mon Nov 02, 2009 11:09 am Post subject: RE:Procedures?!?!?!?!
You could use the concept of threads to do two things at once. However, Turing provides poor support for such concepts, and it is really not needed for what you want to do.
If you expand a bit on what Tony outlined:
Turing:
loop
move_player() if enemy_in_range then
player_attack (enemy) endif
move_enemy() if player_in_range then
enemy_attack (player) endif
delay()% this is the only delay you should have in your program endloop
The execution of the procedures does not happen at the same time. However, if they are efficient enough (ei. not taking too long to execute) than you shouldn't see too much delay between move and attack.
Euphoracle
Posted: Mon Nov 02, 2009 11:54 am Post subject: Re: RE:Procedures?!?!?!?!
Chaoskiller @ Mon Nov 02, 2009 9:56 am wrote:
Euphoracle @ Mon Nov 02, 2009 8:04 am wrote:
Just out of curiosity, what's the point of dividing an integer by 1?
I'm not too sure, I dont undertsand everything all i know is it doesnt work without that. Also i think it means that you are dividing the "for" by 1 if i was to make it div 8 the frames would appear faster and skip a lot.
Tony how is it possible to make 2 things happen at once then?
I need a delay in my animation in order for it to look normal so i cant make them happen as fast as possible.
Rather than having your animation in the procedure doing the "thinking" for that particular thing, have a procedure that draws all the animations as another procedure. In fact, you can use this method to sync the animations so frame 1 is animated to frame to in unison with all animations. Think as such:
Turing:
var AnimFrame :=0 var AnimFrameMax :=25 var..your other vars here..:= whatever
proc Animation
AnimFrame =(AnimFrame + 1)mod(AnimFrameMax + 1)% keeps it in [0, AnimFrame]
DrawRobots
DrawPlayer %write these \/
DrawSomethingElse
DrawSomeMoreStuff
end Animation
proc DrawRobots
Sprite.BlahBlahblah(Blah)%your other sprite stuff excluding the animation Sprite.Animate(enemyrobot, Enemyrobot(AnimFrame), robotx, roboty, false) end DrawRobots
%game loop loop
Player %this is your player stuff like movement etc
EnemyRobots %this is your robot stuff like movement, ai, whatnot
Animation
Time.DelaySinceLast(20)%this delay will keep ALL animations at a good speed endloop
EDIT: I should explain Time.DelaySinceLast; basically, if it takes longer than 1ms to draw everything, it will delay less with a max delay of 20 and a min delay of 0. This makes it look constant by updating the screen every 20 rather than every 20 + processing time (which makes it look mad choppy)
Chaoskiller
Posted: Mon Nov 02, 2009 4:00 pm Post subject: RE:Procedures?!?!?!?!
a lil confused about the whole process thing u did but the time delaysincelast is more clear to me now
Euphoracle
Posted: Mon Nov 02, 2009 10:12 pm Post subject: RE:Procedures?!?!?!?!
Oh, proc is just shorthand for procedure.
Sponsor Sponsor
Chaoskiller
Posted: Mon Nov 02, 2009 11:00 pm Post subject: Re: RE:Procedures?!?!?!?!
Euphoracle @ Mon Nov 02, 2009 10:12 pm wrote:
Oh, proc is just shorthand for procedure.
ooh omg it makes so much more sense. I was putting in process instead and was getting all these errors lmao . Is this the only way to do 2 things at once?
Euphoracle
Posted: Tue Nov 03, 2009 10:33 am Post subject: RE:Procedures?!?!?!?!
Well, you're not doing more than once thing at once, but you are doing everything one step at a time in unison rather than doing one thing, then the next, and the next, etc.
This is the only good way of doing two things at once that doesn't cause problems and inconsistencies.
Chaoskiller
Posted: Tue Nov 03, 2009 10:51 pm Post subject: RE:Procedures?!?!?!?!
ugh i hate this its so dumb how u cant do 2 things at once without problems. Or else it would be so easy to do things
Tony
Posted: Tue Nov 03, 2009 11:11 pm Post subject: RE:Procedures?!?!?!?!
Posted: Tue Nov 03, 2009 11:33 pm Post subject: Re: RE:Procedures?!?!?!?!
Chaoskiller @ Tue Nov 03, 2009 10:51 pm wrote:
ugh i hate this its so dumb how u cant do 2 things at once without problems. Or else it would be so easy to do things
One question, why do you think you need two processes running at once? It seems to me that all you are doing is moving a sprite around the screen, and, if a certain condition comes true, executing an attack animation immediately after. If you have coded your program efficiently you should be able to create the illusion that the attack and walk animations are happening at the same time.
Tony
Posted: Wed Nov 04, 2009 12:16 am Post subject: RE:Procedures?!?!?!?!
If you are to use View.Update it's not even an "illusion", as the entire frame would render only after every element is updated. In such a way, everything would be drawn to screen "at the same time".
Posted: Wed Nov 04, 2009 8:55 am Post subject: Re: RE:Procedures?!?!?!?!
Chaoskiller @ Tue Nov 03, 2009 10:51 pm wrote:
ugh i hate this its so dumb how u cant do 2 things at once without problems. Or else it would be so easy to do things
If I ask you to list the alphabet backwards, forwards, and provide me the first 27 terms of ...
Can you do it? Well yeah, of course you can, one at a time, step by step. you'd figure out Z, then A, then whatever the first term would be given values for n and x and move to the next step of each problem. The computer has a brain like you do. It's very good at figuring things out, but it can only do one thing at a time. It can't multitask instantaneous, just like we can't, but it can if you do it the way you would yourself. This is why the computer cannot do everything at the same time. Sure, you can write everything up in different threads and have them execute at roughly the same time but therein lies the problem.
Imagine you couldn't control whether you were going to get the first letter of the alphabet second. Let's say you wrote down Z and Y immediately, then A then the first term (going back to my example above). You're out of sync. Now, if you continue at this pace or a regular pace, you'll finish the alphabet first. This is no problem to you but a computer doesn't know what to do when something goes wrong. It won't even know something went wrong. When you ask Turing to do everything at once, it does it in whatever order it wants and it doesn't ensure anything happens first, last, or at all. It's possible that your background image can draw over your "robots" if you ask the computer to manage the order. You really don't want to let the computer decide the order of doing things for you, because if it's doing it wrong it is a complete and utter nightmare to find and fix the bug.
So yes, you can get it to do two things at once, but similar to how your mind works, it will work erratically and probably cough up something you didn't want... and some blood.