Author Topic: ※ Danmakufu Q&A/Problem thread 3 ※  (Read 489645 times)

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1170 on: April 27, 2018, 05:42:57 PM »
I've read your tutorials, and merged both the Item Task and Item Const in a single script, and made some code to apply my tasks and item collection with events, as seen here, but my item graphics are not appearing (but the "out" is).
Discovered the bug, but I can't fix it.
It happens when I set the item as a variable like:
Code: [Select]
let obj = CreateItemU1(things);
How can I fix it?

JDude :3

  • tururu
  • boy with code
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1171 on: April 28, 2018, 01:06:33 AM »
How can I make bullet trails?
"dnh is hard" - said no one
"dnh is bullshit" - everyone making a creative pattern

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1172 on: April 28, 2018, 02:25:06 AM »
How can I make bullet trails?
I've seen a example of the kind of code that you want here.
You maybe will have to see some post before this one.

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1173 on: April 28, 2018, 04:09:37 AM »
Oh, random question. How the heck do I put a backslash in a char? '\' escapes the close ', '\\' throws an exception for being too long to go in a char, and let temp="\\"; temp[0] throws an exception as well.
Code: [Select]
"\\ "[0] ?
lol
If you need it for comparison purposes or something you can also cast characters into integers by char+0.

Discovered the bug, but I can't fix it.
It happens when I set the item as a variable like:
Code: [Select]
let obj = CreateItemU1(things);
How can I fix it?
Code: [Select]
ObjRender_SetScaleXYZ(obj,0.1,0.1,0)You set the z-scale for everything to 0 which like any other dimension makes it 0 length. It should be 1.
It only "bugs" when you assign the ID to a variable because otherwise the function doesn't act on it, of course.

Also you have a heck of a lot of code duplication.  You could very easily make it a lot more compact with
Code: [Select]
task SpawnItem(type,x,y,score,delay){
    loop(delay){yield;}
    let h1 = 0;
    let obj = CreateItemU1(type,x,y,score);
    let objRZAngle = ObjRender_GetAngleZ(obj);
    let objRYAngle = ObjRender_GetAngleY(obj);
    let objRXAngle = ObjRender_GetAngleX(obj);
    ObjRender_SetScaleXYZ(obj,0.1,0.1,1);
    ascent(i in 0..60){
        ObjRender_SetAngleZ(obj,objRZAngle+i*720/60+12);
        ObjRender_SetScaleXYZ(obj,(1.7/30)*i/2,(1.7/30)*i/2,1);
        yield;
    }
    loop{
        yield;
        ObjRender_SetAngleY(obj,objRYAngle+h1*6);
        h1++;
    }
}
// and then optionally
function SpawnLife(x,y,score,delay){
    SpawnItem(ITEM_LIFE_B,x,y,score,delay);
}
function SpawnSpell(x,y,score,delay){
    SpawnItem(ITEM_SPELL_B,x,y,score,delay);
}
// etc

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1174 on: April 29, 2018, 02:14:50 AM »
Code: [Select]
ObjRender_SetScaleXYZ(obj,0.1,0.1,0)You set the z-scale for everything to 0 which like any other dimension makes it 0 length. It should be 1.
It only "bugs" when you assign the ID to a variable because otherwise the function doesn't act on it, of course.

Also you have a heck of a lot of code duplication.  You could very easily make it a lot more compact with
Code: [Select]
code
The bug was still in action when I do the let obj = CreateItemU1 OUTSIDE of the task, and when I change the Z-scale to 1, the outside of the stage(the frame) is turned to black.
Before I actually made a item script, I still had that bunch of tasks, and everything worked correctly. The problem started when I transferred the tasks into the item script.

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1175 on: April 29, 2018, 07:01:03 AM »
and when I change the Z-scale to 1, the outside of the stage(the frame) is turned to black.
wat

Can you just upload your folder or something, this is too strange for me to speculate about.

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

SusiKette

  • @MainLoop { yield; }
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1176 on: April 29, 2018, 02:48:44 PM »
I got this error message and I haven't found any place that explains what it means:

敵ライフを適切に返していません。(D:/th_dnh_ph3/script/test_script/Spell01.txt)

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1177 on: April 29, 2018, 02:57:17 PM »
wat

Can you just upload your folder or something, this is too strange for me to speculate about.
Here

SusiKette

  • @MainLoop { yield; }
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1178 on: April 29, 2018, 03:00:15 PM »
Never mind about my last post. Its not an issue for now. My next question is how do I store the shot id of the previously created shot?
Apparently this doesn't work.
Code: [Select]
CreateShotA1(BossX, BossY, 2, AimPlayer(), DS_BALL_S_RED, 10);
shot_id = return;

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1179 on: April 29, 2018, 04:25:30 PM »
Code: [Select]
let shot_id = CreateShotA1(BossX, BossY, 2, AimPlayer(), DS_BALL_S_RED, 10);
CreateShotA1 is a built-in function that returns an Integer (Object ID) as a return type. You can store this return value in a variable.
« Last Edit: April 29, 2018, 04:27:40 PM by Sparen »

SusiKette

  • @MainLoop { yield; }
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1180 on: April 29, 2018, 04:38:36 PM »
I guess I thought that using return; would be the value of the last thing a function returned.
My next question is that how you can make a bullet fly in a wavy motion? I know I need to use ObjMove_SetAngularVelocity(id, r);. I was hoping to make it so that the wavy motion started small and as the bullet travels further, the it would start waving further to each side.

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1181 on: April 29, 2018, 05:38:03 PM »
I guess I thought that using return; would be the value of the last thing a function returned.
My next question is that how you can make a bullet fly in a wavy motion? I know I need to use ObjMove_SetAngularVelocity(id, r);. I was hoping to make it so that the wavy motion started small and as the bullet travels further, the it would start waving further to each side.
You can make a task that plays a descent loop, and make that the bullet have a angular velocity, then wait, then have the same angular velocity, but negative.
You can increase the "waving" motion with the descent loop variable, like this:
Code: [Select]
task Waving(obj){
descent(i in 0..100){//a really big number to make things to not stop waving(number of times the bullet will wave)
ObjMove_SetAngularVelocity(obj,i/10);
loop(180/(i/10)){yield;}
ObjMove_SetAngularVelocity(obj,i/-10);
loop(180/(i/10)){yield;}
}
}

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1182 on: April 29, 2018, 10:10:26 PM »
How would I add a sprite for a boss that is in a sprite sheet?

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1183 on: April 29, 2018, 11:43:17 PM »
I guess I thought that using return; would be the value of the last thing a function returned.
My next question is that how you can make a bullet fly in a wavy motion? I know I need to use ObjMove_SetAngularVelocity(id, r);. I was hoping to make it so that the wavy motion started small and as the bullet travels further, the it would start waving further to each side.

You should make the change angular velocity as well as the time between shifts dependent on time. I would have a descent loop that waits the number of frames in the loop constant, with the angular velocity likewise being dependent on the constant.

EDIT: Didn't realize there was already a code-based answer

How would I add a sprite for a boss that is in a sprite sheet?

What are you trying to do? If you have a sprite sheet and want to animate the boss, then you'll need to determine the dimensions of each sprite, then change the source rect in your Render Object depending on how much time has passed.

Below is an example the code I use. I have 4 128x128 sprites in a row that form the animation, and four states to represent idle/left/right/cast (the first row is idle, the second is left, etc). I've removed the cast/attack animation logic from the snippet below to make it shorter.

Code: [Select]
    let TDRAWSTATE_IDLE = 0;
    let TDRAWSTATE_LEFT = 1;
    let TDRAWSTATE_RGHT = 2;

    task TDrawLoop(path){
        let animframe = 1;
        let movestate = TDRAWSTATE_IDLE;
        ObjPrim_SetTexture(objBoss, path);
        ObjRender_SetScaleXYZ(objBoss, 1, 1, 1);
        let bossAngle = ObjMove_GetAngle(objBoss);
        let bossSpeed = ObjMove_GetSpeed(objBoss);
        ObjSprite2D_SetSourceRect(objBoss, 0, 0, 128, 128);
        ObjSprite2D_SetDestCenter(objBoss);
        while(!Obj_IsDeleted(objBoss)){
            bossAngle = ObjMove_GetAngle(objBoss) % 360;
            bossSpeed = ObjMove_GetSpeed(objBoss);

            if(bossSpeed > 0){ //below three cases require if statement to prevent reset of animframe.
                if((bossAngle > 270 || bossAngle < 90) && movestate != TDRAWSTATE_RGHT){
                    movestate = TDRAWSTATE_RGHT;
                    animframe = 0;
                }else if((bossAngle > 90 && bossAngle < 270) && movestate != TDRAWSTATE_LEFT){
                    movestate = TDRAWSTATE_LEFT;
                    animframe = 0;
                }else if((bossAngle == 90 || bossAngle == 270) && movestate != TDRAWSTATE_IDLE){
                    movestate = TDRAWSTATE_IDLE;
                    animframe = 0;
                }
            }else if(movestate != TDRAWSTATE_IDLE){ //if transitioning back to idle (speed = 0)
                movestate = TDRAWSTATE_IDLE;
                animframe = 0;
            }

            ObjSprite2D_SetSourceRect(objBoss, 0+floor(animframe/9)*128, 0 + 128*movestate, 128 + floor(animframe/9)*128, 128 + 128*movestate);

            animframe++;
            if(animframe >= 36){
                if(movestate == TDRAWSTATE_IDLE){ //animframe reset for idle
                    animframe = 0;
                }else{ //keep in current position if moving.
                    animframe = 35;
                }
            }
            yield;
        }
    }

Essentially, we have 128x128 sprites and the one we choose is dependent on animframe (9 frames per image, 4 images = 36 frames before we reset the idle animation). For my left and right movement, I keep the animation in the last image after the opening sequence plays, hence maintaining animframe at 35 at the end. If the boss is not moving, then they will not be kept in a movement state.

The line that handles choosing which sprite to use is the following:
ObjSprite2D_SetSourceRect(objBoss, 0+floor(animframe/9)*128, 0 + 128*movestate, 128 + floor(animframe/9)*128, 128 + 128*movestate);

floor(animframe/9)*128 represents which frame to use (first, second, third, or fourth) in the spreadsheet, while 128*movestate represents which animation to use (idle, left, right, or cast).

I hope this gives you a better sense of how to animate your sprite sheet.
« Last Edit: April 29, 2018, 11:55:09 PM by Sparen »

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1184 on: April 30, 2018, 01:26:49 AM »
Yes that was exactly what i needed, thank you. This is going to sound like a dumb question ,but are the (path) parts referring to the path to the image or the TDRAWSTATES?

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1185 on: April 30, 2018, 01:31:11 AM »
Yes that was exactly what i needed, thank you. This is going to sound like a dumb question ,but are the (path) parts referring to the path to the image or the TDRAWSTATES?
To the path to image.

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1186 on: April 30, 2018, 05:32:19 AM »
And I have one more problem.
I have a function that spawns a enemy object like a bullet, and I can set the life, the angle, etc. like a bullet.
But when I set the life and shoot it, the life seems do not go down.
Here is the link to the functions.
« Last Edit: April 30, 2018, 02:43:25 PM by Zinochan »

Mellow

  • A Kid, Just a kid.....
  • Is that a Touhou reference?!
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1187 on: April 30, 2018, 05:42:55 AM »
I'm having problem with finding my script in general.

I have a folder called "mine" in the scripts folder, and my .txt file script in "mine"
when i launch ph3, my .txt file doesn't show. i think i'm doing something wrong, but I don't know what...  :matsuriscowl:
frick AND heck!

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1188 on: April 30, 2018, 05:43:57 AM »
Do the bullets go through the enemy or stop at it?

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1189 on: April 30, 2018, 05:55:02 AM »
Do the bullets go through the enemy or stop at it?
They stop.

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1190 on: April 30, 2018, 06:47:06 AM »
Here
First, you write let obj = 0; and then proceed to manipulate obj. 0 is the ID of an object; it isn't just nothing! Use -1 if you want to use a dummy value for referencing objects. This is why you're getting the bad STG frame.

Second, the reason your stuff wouldn't work properly once you put the item object in the variable is because you have no MainLoop in the item script and therefore no yield in your MainLoop, so none of your tasks will progress.

Third, as a precaution using loop is bad here because there is no way to exit and so the tasks will live as long as the script does.

Here is a small rewrite, including the suggestion I made earlier (add a yielded MainLoop):
Code: [Select]
task SpawnItem(type, x, y, score, delay){
loop(delay){yield;}
let obj = CreateItemU1(type, x, y, score);
ascent(i in 0..60){
ObjRender_SetAngleZ(obj, 2*(720/60)*i);
ObjRender_SetScaleXYZ(obj, 0.1+(0.9/60)*i, 0.1+(0.9/60)*i, 1);
yield;
}
ObjRender_SetAngleZ(obj, 0);
ObjRender_SetScaleXYZ(obj, 1, 1, 1);
let h1 = 0;
while(!Obj_IsDeleted(obj)){
ObjRender_SetAngleY(obj, h1*6);
h1++;
yield;
}
}
function SpawnLife(x, y, score, delay){
SpawnItem(ITEM_LIFE_B, x, y, score, delay);
}
function SpawnLifePiece(x, y, score, delay){
SpawnItem(ITEM_LIFE_B_P, x, y, score, delay);
}
function SpawnSpell(x, y, score, delay){
SpawnItem(ITEM_SPELL_B, x, y, score, delay);
}
function SpawnSpellPiece(x, y, score, delay){
SpawnItem(ITEM_SPELL_B_P, x, y, score, delay);
}
You could then also trim your event cases with
Code: [Select]
case(EV_USER+1000){ // Spawn Item event
let args = GetEventArgument(0);
SpawnItem(args[0], args[1], args[2], args[3], args[4]); // type, x, y, score, delay
}
« Last Edit: April 30, 2018, 07:11:26 AM by Drake »

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1191 on: April 30, 2018, 07:18:10 AM »
And I have one more problem.
I have a function that spawns a enemy object like a bullet, and I can set the life, the angle, etc. like a bullet.
But when I set the life and shoot it, the life seems do not go down.
Here[url] is the link to the functions.
The delete-when-0-life task just checks once and then immediately ends. Should be
Code: [Select]
task DeleteEnemyWhenLife0(obj){
while(ObjEnemy_GetInfo(obj,INFO_LIFE) > 0){ yield; }
Obj_Delete(obj);
}

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

SusiKette

  • @MainLoop { yield; }
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1192 on: April 30, 2018, 10:23:32 AM »
You can make a task that plays a descent loop, and make that the bullet have a angular velocity, then wait, then have the same angular velocity, but negative.
You can increase the "waving" motion with the descent loop variable, like this:
Code: [Select]
task Waving(obj){
descent(i in 0..100){//a really big number to make things to not stop waving(number of times the bullet will wave)
ObjMove_SetAngularVelocity(obj,i/10);
loop(180/(i/10)){yield;}
ObjMove_SetAngularVelocity(obj,i/-10);
loop(180/(i/10)){yield;}
}
}

The bullet is doing a wavy motion, but its I don't see a change in the interval the motion is reversed. I tried changing the values but I'm not able to get it to work that way either.

JDude :3

  • tururu
  • boy with code
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1193 on: April 30, 2018, 01:43:58 PM »
Still having problems with multi phased nonspells/spells, it doesn't work....
Here is a part of my script
"dnh is hard" - said no one
"dnh is bullshit" - everyone making a creative pattern

CrestedPeak9

  • Fangame Advocate
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1194 on: April 30, 2018, 02:04:06 PM »
Still having problems with multi phased nonspells/spells, it doesn't work....
Here is a part of my script

I see literally nothing in that script that compares boss health against a constant except for preventing 0,0 spawning...
Lunatic 1cc: EoSD, PCB, IN, MoF, TD, DDC, LoLK, HSiFS, WBaWC

JDude :3

  • tururu
  • boy with code
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1195 on: April 30, 2018, 02:20:29 PM »
I see literally nothing in that script that compares boss health against a constant except for preventing 0,0 spawning...
I don't get it, what should I do?
"dnh is hard" - said no one
"dnh is bullshit" - everyone making a creative pattern

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1196 on: April 30, 2018, 03:02:06 PM »
First, you write let obj = 0; and then proceed to manipulate obj. 0 is the ID of an object; it isn't just nothing! Use -1 if you want to use a dummy value for referencing objects. This is why you're getting the bad STG frame.

Second, the reason your stuff wouldn't work properly once you put the item object in the variable is because you have no MainLoop in the item script and therefore no yield in your MainLoop, so none of your tasks will progress.

Third, as a precaution using loop is bad here because there is no way to exit and so the tasks will live as long as the script does.

Here is a small rewrite, including the suggestion I made earlier (add a yielded MainLoop):
Code: [Select]
task SpawnItem(type, x, y, score, delay){
loop(delay){yield;}
let obj = CreateItemU1(type, x, y, score);
ascent(i in 0..60){
ObjRender_SetAngleZ(obj, 2*(720/60)*i);
ObjRender_SetScaleXYZ(obj, 0.1+(0.9/60)*i, 0.1+(0.9/60)*i, 1);
yield;
}
ObjRender_SetAngleZ(obj, 0);
ObjRender_SetScaleXYZ(obj, 1, 1, 1);
let h1 = 0;
while(!Obj_IsDeleted(obj)){
ObjRender_SetAngleY(obj, h1*6);
h1++;
yield;
}
}
function SpawnLife(x, y, score, delay){
SpawnItem(ITEM_LIFE_B, x, y, score, delay);
}
function SpawnLifePiece(x, y, score, delay){
SpawnItem(ITEM_LIFE_B_P, x, y, score, delay);
}
function SpawnSpell(x, y, score, delay){
SpawnItem(ITEM_SPELL_B, x, y, score, delay);
}
function SpawnSpellPiece(x, y, score, delay){
SpawnItem(ITEM_SPELL_B_P, x, y, score, delay);
}
You could then also trim your event cases with
Code: [Select]
case(EV_USER+1000){ // Spawn Item event
let args = GetEventArgument(0);
SpawnItem(args[0], args[1], args[2], args[3], args[4]); // type, x, y, score, delay
}
Oh, now I understand, and I don't get why your SpawnLife/Spell is a function. Can't it be a task?
And I've completely forgot about the MainLoop.
Now the code works correctly.
Thank you.

Gregory

  • I draw stuffs
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1197 on: April 30, 2018, 04:31:41 PM »
I don't get it, what should I do?

you should write a more specific health check from the Boss that does something from A to B  and if it passes the 1st threshold it will do the next from B to C
Code: [Select]
while(ObjEnemy_GetInfo(enm,INFO_LIFE)>=7000){

yield;}

while(ObjEnemy_GetInfo(enm,INFO_LIFE)<=7000 && ObjEnemy_GetInfo(enm,INFO_LIFE)>= 4500){

yield;}

« Last Edit: April 30, 2018, 04:34:31 PM by Gregory »

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1198 on: April 30, 2018, 06:53:39 PM »
I am trying to recreate something similar to Mokou's first non-spell, to create the rows of bullets would you use ascent loops and loose lasers or is there a better way to do that.

JDude :3

  • tururu
  • boy with code
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1199 on: April 30, 2018, 09:36:41 PM »
you should write a more specific health check from the Boss that does something from A to B  and if it passes the 1st threshold it will do the next from B to C
That's not what I want; what I'm looking for is nons/spells like this
"dnh is hard" - said no one
"dnh is bullshit" - everyone making a creative pattern