| ~Hakurei Shrine~ > Rika and Nitori's Garage Experiments |
| Danmakufu Q&A/Problem Thread |
| (1/201) > >> |
| Darkblizer:
Hey, I just decided I'd make a place where people can ask questions and post their problems, hopefully to be answered. I might be able to answer some, but first, I have a question of my own. What's the difference between a sub, a task, and a function? they seem to be used in similar ways. |
| Naut:
In order of processing speed, from fastest to slowest: sub function task And here's why. A sub is just a routine that you often call that requires no changing whatsoever. So if I wanted to make the same array of shots happen over and over again, but at different places in the script, I could say somewhere in script_enemy_main: --- Code: ---sub bullatz{ CreateShot01(GetX, GetY, 3, GetAngleToPlayer - 30, RED02, 0); CreateShot01(GetX, GetY, 3, GetAngleToPlayer - 20, RED02, 0); CreateShot01(GetX, GetY, 3, GetAngleToPlayer - 10, RED02, 0); CreateShot01(GetX, GetY, 3, GetAngleToPlayer, RED02, 0); CreateShot01(GetX, GetY, 3, GetAngleToPlayer + 10, RED02, 0); CreateShot01(GetX, GetY, 3, GetAngleToPlayer + 20, RED02, 0); CreateShot01(GetX, GetY, 3, GetAngleToPlayer + 30, RED02, 0); } --- End code --- And then say bullatz; anywhere in my script and those shots will be fired. A function is the same thing, except you can edit parameters of the shots as you're calling them. So, to fire a similar array of shots: --- Code: ---function bullutz(angle){ CreateShot01(GetX, GetY, 3, angle - 30, RED02, 0); CreateShot01(GetX, GetY, 3, angle - 20, RED02, 0); CreateShot01(GetX, GetY, 3, angle - 10, RED02, 0); CreateShot01(GetX, GetY, 3, angle, RED02, 0); CreateShot01(GetX, GetY, 3, angle + 10, RED02, 0); CreateShot01(GetX, GetY, 3, angle + 20, RED02, 0); CreateShot01(GetX, GetY, 3, angle + 30, RED02, 0); } --- End code --- This time, I'll call bullutz(90); to shoot this array of bullets with the updated angle of 90 degrees. I could say bullutz(270); for another direction. And that's what functions are in Danmakufuland. Ah, you can also call more than one paramter in a function, so don't feel limited by only one independent variable. A task, as you might guess, is an upgraded function, and thus takes the most processing power. With tasks you are basically creating another @MainLoop that you control whenever it's run. To do this, tasks use the magical operator called yield;. yield; allows you to freely switch between processing your task and processing your @MainLoop, so you can list ordered events, and have them only carry out your actions once without repeat, and still edit them. yield; suspends the current task or MainLoop and then carries onto another task until it hits another yield; command, then it goes back to the MainLoop and finishes the frame cycle. It'll continue where it left off the next frame, which makes it very easy to list ordered events. A task is basically a list of events that you want to happen, that you can freely edit at anytime during the script using the same parameters as a function. And an example of a task: --- Code: ---task attack(delay, angle){ CreateShot01(GetX, GetY, 5, GetAngleToPlayer, RED03, delay); loop(120){yield;} loop(5){ CreateShot01(GetX, GetY, 3, GetAngleToPlayer, BLUE01, 0); loop(5){yield;} } CreateShot01(GetX, GetY, 2, angle, YELLOW12, 0); } --- End code --- So now, I'll call attack(5, 90); somehwere in @MainLoop to fire of a large red shot towards the player with 5 delay, the script will wait two seconds (120 frames, the loop(120){yield;} statement), then fire 5 blue shots in succession but wait 5 frames inbetween each shot, and then finally firing a small yellow shot at 90 degrees. It should be noted that you MUST include yield; somewhere in your @MainLoop (preferably at the beginning or end, easier to keep track of) and call it every frame to ensure that the yield; command works properly in your tasks. Anyways, you probably already knew about yield; and crap, but I thought I would be clear with the explanation and include everything, even though this is a very poor description of the yield; command and what it does. |
| Naut:
I'll contribute with my own question now, I suppose. Does GetAngleToPlayer output a value between 0 and 360, a value between -180 and 180, or something else? Does atan2() have the same output parameters? |
| Drake:
There's a way to check. Spawn a bullet with the delay time GetAngleToPlayer, but stand in the upper right corner. Similarly you could set it to atan2(player-boss, player-boss). Obviously if you get an error it's a negative value. |
| Stuffman:
As far as I know whenever the engine outputs an angle it's in the -180 to 180 range, even though it accepts any degree amount you put in. |
| Navigation |
| Message Index |
| Next page |