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

tsunami3000

  • Touhou is cool i guess
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1680 on: February 08, 2019, 01:46:29 PM »
Hi! I just wanted to ask how I could create a custom life system, specifically a system with life pieces, like SA or UFO. I understand the answer is probably too complex, so I'd be okay with just knowing the general idea behind it, or like, what aspects of danmakufu should I have no problems with before I attempt to code said system.
Also, I haven't been able to find any tutorial on the matter, but if you know one, I'd be happy with just that!
« Last Edit: February 08, 2019, 07:17:44 PM by tsunami3000 »
some day i'll finally beat UFO... some day

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1681 on: February 08, 2019, 10:31:50 PM »
Hi! I just wanted to ask how I could create a custom life system, specifically a system with life pieces, like SA or UFO. I understand the answer is probably too complex, so I'd be okay with just knowing the general idea behind it, or like, what aspects of danmakufu should I have no problems with before I attempt to code said system.
Also, I haven't been able to find any tutorial on the matter, but if you know one, I'd be happy with just that!

In general, you will need to utilize CommonData to store information on the life pieces, as well as custom items to support them.

Unfortunately this is a relatively advanced topic. For reference:
https://sparen.github.io/ph3tutorials/ph3u3l24.html (CommonData)
https://sparen.github.io/ph3tutorials/ph3u3l25.html (Events)
https://sparen.github.io/ph3tutorials/ph3u3l26.html (User Events)
https://sparen.github.io/ph3tutorials/ph3u3l27.html (Items)

tsunami3000

  • Touhou is cool i guess
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1682 on: February 10, 2019, 02:11:48 PM »
In general, you will need to utilize CommonData to store information on the life pieces, as well as custom items to support them.

Unfortunately this is a relatively advanced topic. For reference:
https://sparen.github.io/ph3tutorials/ph3u3l24.html (CommonData)
https://sparen.github.io/ph3tutorials/ph3u3l25.html (Events)
https://sparen.github.io/ph3tutorials/ph3u3l26.html (User Events)
https://sparen.github.io/ph3tutorials/ph3u3l27.html (Items)

Thanks a lot!
some day i'll finally beat UFO... some day

Crescendo

  • Trying to be a little less lazy
  • ;
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1683 on: February 20, 2019, 04:48:22 AM »
Hello again.

I've been working on a pretty complex spell recently, but a section is giving me issues. I'll give a simpler version since the actual code is decently big:

Code: [Select]
basicbul(100, 100); //Calls the  "absorption" bullet and it's x/y coordinates.

task basicbul(xa, ya){
              CreateShotA1( xa, ya, 0, GetAngleToPlayer(objBoss), 20, 15); //Absorption bullet's creation
              undefinedFantasticObject(xa, ya); //calls for the bullets being absorbed
}

task undefinedFantasticObject(xa, ya){
let xb = 300; //creates the x/y values for the aborbed bullets
let yb = 100;
let UFO = CreateShotA1( xb, yb, 2, 180, 3, 15);//creates said bullets
if(xa && ya == xb && yb){
Obj_Delete(UFO); //boolean that says "If bullet a's x/y values are the same as bullet b's x/y values, delete bullet b. *What's not working*
       }
}


Essentially, I'm trying to create a bullet that, when another bullet reaches the center of it, the bullet "absorbs" the other bullet and grows a certain amount. I'm trying to let the boolean compare the two x/y values, but no dice. Nothing happens. Strangely, if I switch the xa/ya and xb/yb around, it does the exact opposite and deletes immediately. Even with a wait, it will delete after the wait is over, and nowhere near the absorption bullet.

Granted, it is my first time with booleans in danmakufu, but I've seen it many times before, so I don't believe it's the structure. After looking over it myself and other's script that worked with booleans similarly, I'm not sure if it's the location of the boolean or something's wrong with the variables. Can someone look this over? Thanks in advance.
Normal 1cc's: EoSD(RA), PCB(SA), IN(BT), MoF(RA), SA(MC), UFO(RB), TD(R), DDC(SA), PDLoLK(Reimu, 921 tries), HSiFS(CWin)
Fangame 1cc's: HSoB-Normal(SPurple,KWhite)
Current goals:  EoSD hard, EoSD extra.
Attempting the art of danmakufu.

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1684 on: February 20, 2019, 07:16:12 AM »
That way of phrasing the position check is incorrect. You want (xa == xb && ya == yb).

Also, xa, ya, xb, yb are just numbers. They aren't going to be updated with the bullet's new positions just because you spawned a bullet at those coordinates. Instead you need to work with the bullet objects you're creating. The ObjMove_GetX/Y functions are what will give you a bullet's current position. You can do something like this:

Code: [Select]
basicbul(100, 100); //Calls the  "absorption" bullet and it's x/y coordinates.

task basicbul(xa, ya){
let absorber = CreateShotA1( xa, ya, 0, GetAngleToPlayer(objBoss), 20, 15);
undefinedFantasticObject(absorber); //calls for the bullets being absorbed
}

task undefinedFantasticObject(absorber){
let UFO = CreateShotA1(300, 100, 2, 180, 3, 15);
if(ObjMove_GetX(absorber) == ObjMove_GetX(UFO) && ObjMove_GetY(absorber) == ObjMove_GetY(UFO)){
Obj_Delete(UFO);
}
}

This will probably have its own problem, but I want to see how much this does first.

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

Crescendo

  • Trying to be a little less lazy
  • ;
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1685 on: February 20, 2019, 10:18:20 PM »
That way of phrasing the position check is incorrect. You want (xa == xb && ya == yb).

Also, xa, ya, xb, yb are just numbers. They aren't going to be updated with the bullet's new positions just because you spawned a bullet at those coordinates. Instead you need to work with the bullet objects you're creating. The ObjMove_GetX/Y functions are what will give you a bullet's current position.

Thanks for the variable information! I'll keep that in mind for future uses.

I got it to work, but weirdly I had to throw it in a separate task that looped for it to do it. Earlier I added an else statement to play a noise see if the boolean was even working, and it only went off once. From what I've seen from other scripts, booleans didn't seem to need a separate loop, which kinda weirds me out.

I can work with this, but is the looping part normal? Just want to make sure  :V

Normal 1cc's: EoSD(RA), PCB(SA), IN(BT), MoF(RA), SA(MC), UFO(RB), TD(R), DDC(SA), PDLoLK(Reimu, 921 tries), HSiFS(CWin)
Fangame 1cc's: HSoB-Normal(SPurple,KWhite)
Current goals:  EoSD hard, EoSD extra.
Attempting the art of danmakufu.

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1686 on: February 21, 2019, 01:40:44 AM »
Oh uh yes. I'm dumb and didn't put it in. Should wrap the collision check in while(!Obj_IsDeleted(absorber) && !Obj_IsDeleted(UFO)) and toss a yield in there. That way it checks every frame.

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

Crescendo

  • Trying to be a little less lazy
  • ;
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1687 on: February 21, 2019, 02:33:27 AM »
Oh uh yes. I'm dumb and didn't put it in. Should wrap the collision check in while(!Obj_IsDeleted(absorber) && !Obj_IsDeleted(UFO)) and toss a yield in there. That way it checks every frame.

No worries! Works like a charm, thank you for your help!

Edit: Ok, so I was trying to implement it into my spell and I have a question. Does randomness mess with the boolean? In the spell, the bullets come from different, randomized angles, yet eventually reach the center of the bullet, so it shouldn't be a big deal. Yet the boolean ignores that and doesn't run unless nothing is random. Can even confirm it's the randomness after a quick test:

Code: [Select]
let x = rand(200,200); //works
let x = rand(200,201); //doesn't work, despite the probability that 50% of the bullets should be deleted.

Sorry if I'm getting annoying at this point, but I'm too stubborn to let this spell concept go  :V I have looked for scripts with similar spells to possibly work from but have yet to find one...
« Last Edit: February 21, 2019, 05:00:27 AM by Crescendo »
Normal 1cc's: EoSD(RA), PCB(SA), IN(BT), MoF(RA), SA(MC), UFO(RB), TD(R), DDC(SA), PDLoLK(Reimu, 921 tries), HSiFS(CWin)
Fangame 1cc's: HSoB-Normal(SPurple,KWhite)
Current goals:  EoSD hard, EoSD extra.
Attempting the art of danmakufu.

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1688 on: February 21, 2019, 09:30:09 AM »
If I am not mistaking, rand() uses the entered parameter as a float and not an integer. What happens under the hood is that if you enter 200 as a parameter, it is actually initialized as 200.000000 by the engine.

If you use rand(200,201) the engine will actually generate a random number between 200.00000 and 201.000000. So technically the randomized number could be 200.583921. So there is no 50% :V Awesome aint it?

To solve this in my own game, I've created my own rand_int() function (which used to exist in 0.12m). It is actually quite dirty because it truncates the decimal value. Pretty sure someone else has a better suggestion to this.
Code: [Select]
// 0.12m personal transition for rand_int.
function rand_int(min,max) {
let rand_int_result;
rand_int_result = truncate(rand(min,max));
return rand_int_result;
}
« Last Edit: February 21, 2019, 09:57:18 AM by Helepolis »

Crescendo

  • Trying to be a little less lazy
  • ;
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1689 on: February 21, 2019, 01:01:55 PM »
It never once occurred to me decimals would be involved...  :V

I don't have too much time atm so I'll test this when I do and edit this for results later.
Normal 1cc's: EoSD(RA), PCB(SA), IN(BT), MoF(RA), SA(MC), UFO(RB), TD(R), DDC(SA), PDLoLK(Reimu, 921 tries), HSiFS(CWin)
Fangame 1cc's: HSoB-Normal(SPurple,KWhite)
Current goals:  EoSD hard, EoSD extra.
Attempting the art of danmakufu.

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1690 on: February 21, 2019, 02:20:38 PM »
It never once occurred to me decimals would be involved...  :V
:V hehehe

When in doubt, debug out

Honestly, generic advice to all danmakufu folks. Whenever you think values or numbers are acting weird: Debug them as text on your screen. It will help you a ton to understand mindbreaking problems you ran into.

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1691 on: February 21, 2019, 05:04:49 PM »
Hi!, I'm doing a package with only one stage inside of it and for some reason every time I play it in the final main boss part the stage is literally consuming the FPS from 60 to 40, from 40 to 30, from 30 to 18 or less...

I already checked everything, erased stuff, changed the scripts from .dnh to .txt, moved the stage script closer, only used vital effects and placed it all into one single script, didn't cover the whole screen with bullets,in the end I did a big mess inside the main stage, and also checked the player's bomb, bullets, and everything, I dunno what to do there's not much time left, if I cannot fix the FPS I'll be forced to bring this to the public with the only FPS problem due to time issues... :ohdear: :(

Also I'm using a laptop and yes I already checked and did the FPS fix inside it.  Is it due to me using a laptop to make this? :wat: ??? :ohdear:
« Last Edit: February 21, 2019, 05:09:59 PM by Montrek »

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1692 on: February 21, 2019, 06:28:26 PM »
and for some reason every time I play it in the final main boss part the stage is literally consuming the FPS from 60 to 40, from 40 to 30, from 30 to 18 or less...

I've boldfaced your problem for you.

What happens when you play it? What gets loaded? What is unloaded? Are you creating objects that are never deleted? Are you creating tasks that never terminate?

I highly suggest using the built-in Log Window for debugging.

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1693 on: February 21, 2019, 09:24:49 PM »
What gets loaded is a plural script for the boss containing 1 prebattle dialogue, 2 nonspells, 3 spells, and 1 postbattle dialogue after that everything ends the only problem is the FPS...
Oh there's a task that I put to disappear bullets in patterns like in DDC or HSiFS, however yes I already tried doing it without this task...
There's also the items tasks and events that every enemy including the boss has.
There's also HiScore, Score, Lives, Bombs, graze, power and points, and yes I already tried playing it without a few of this...

And how do I get a Log Windows?

Edit:
Alright I found a LogWindow.dat now what do I do with it? :ohdear:
Unless that's not how it's done and is already inside the danmakufu or I must do it myself or something? :wat: ???
I don't know how it's done I'm new at making packages...   :blush: :wat: :ohdear:
« Last Edit: February 22, 2019, 09:28:38 AM by Helepolis »

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1694 on: February 22, 2019, 06:07:34 AM »
And how do I get a Log Windows?
Open config.exe, go to Options and check Show Log Window. Then on launch the log window will appear, and you can check the Info tab for various things.

I agree this is probably a case of objects that continually spawn and are not deleted. You can monitor how many objects exist through the log window and see if they just keep increasing while your script is running.

Ok, so I was trying to implement it into my spell and I have a question. Does randomness mess with the boolean? In the spell, the bullets come from different, randomized angles, yet eventually reach the center of the bullet, so it shouldn't be a big deal.
This goes back to what I said about "this will probably have its own problem". This happens because collisions are more complicated than just position = position. Like Hele says, you could have a position value that is like 200.583921, and that will not be equal to 200. Even if a bullet gets close to the position of the other, the chances they will actually be equal is extremely small unless both bullets are tightly controlled (which is what you saw when you had no randomness and a 180 angle and integer-valued speed).

Instead, collision typically checks if the distance between the two things is less than some amount. You can do this using
if(((x1 - x2)^2 + (y1 - y2)^2)*0.5 < r) or if(GetObjectDistance(obj1, obj2) < r).

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

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1695 on: February 22, 2019, 09:17:43 AM »
Interesting..., apparently what seems to keep increasing but without being erased is the obj_count like more than 7000, but I don't really know how to actually decrease or erase all of that... :ohdear: ??? :wat:
What do I do? Is it inside the script and needs a task or function for this or I'll need some kinda special file? :ohdear: ???
Or erase stuff? :wat:

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1696 on: February 22, 2019, 09:32:56 AM »
Interesting..., apparently what seems to keep increasing but without being erased is the obj_count like more than 7000, but I don't really know how to actually decrease or erase all of that... :ohdear: ??? :wat:
What do I do? Is it inside the script and needs a task or function for this or I'll need some kinda special file? :ohdear: ???
Or erase stuff? :wat:
Can you locate which objects are not deleting? Are they a bunch of bullets that go out of screan frame then move to infinty? Are they primitives for various effect that doesn't get deleted? There are a lot of things that could be causing this.
Edit: Oh wait. Shots and other objects are shown separately in LogWindow, sorry.
« Last Edit: February 22, 2019, 09:36:29 AM by [INSERT USERNAME HERE] »

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1697 on: February 22, 2019, 09:34:48 AM »
You need to control your objects and proper clean them up when they are no longer needed. Objects (effects, bullets etc) created by you are never auto-deleted. Even if they leave the screen.

The default function call for objects is Obj_Delete

Small code example:
Code: [Select]
task someComplexBullet() {
  let obj = ...

  while (!Obj_IsDeleted) {
    // complex behaviour

    if () {
      Obj_Delete(obj);
    }
  }
}
Basically this task creates an object and is doing things while it is not deleted. This could be anything. You need to decide, as a programmer, when this object should be deleted. In the code example I did it with a if-statement, but it could be anything. The goal is to delete the object.


Edit as moderation note:
Do not double post if your post is the last one in the thread. Edit your original post and append your findings and/or questions.

« Last Edit: February 22, 2019, 09:37:55 AM by Helepolis »

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1698 on: February 22, 2019, 08:17:24 PM »
Objects (effects, bullets etc) created by you are never auto-deleted. Even if they leave the screen.

That simply isn't the case for bullets. The default settings have bullets deleting themselves when they move 64 pixels outside the stgframe thingy. Which isn't to say that you might not want to turn off autodelete for a particular group of bullets and manually delete them, but simple bullets shouldn't have that problem.

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1699 on: February 22, 2019, 10:59:15 PM »
Yup it seems like the player shots are not being deleted either, I noticed this cause everytime I shoot into oblivion the obj_count seems to be increasing in a very critical way.
Is there actually something the I can put inside the player? ???

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1700 on: February 23, 2019, 01:01:09 AM »
We'll have to see your scripts to get an idea of what you aren't deleting. Player shots should also automatically be deleted going out of bounds, so...

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

HumanReploidJP

  • The Scripter with Something of Common Sense
  • "Start the life of an idol! Let's get STAR~ted!"
    • HumanReploidJP's Youtube Channel
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1701 on: February 23, 2019, 01:34:27 PM »
Hmm... I have a question:

What's the purpose of creating a bullet pattern that goes in a 3D geometric shape (i.e., a 3D sphere, and even this: https://youtu.be/E_ODbJzyqbA?t=360)?

If you have an example and a formula of it, let me know.
Please respond.
MiraikeiBudoukan (Futuristic Vineyard) Game Concepts (WIP)
(Non-Touhou, yet bullet-hell-Inspirable (Like JynX). Don't get serious.)

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1702 on: February 25, 2019, 05:59:40 AM »
What's the purpose of creating a bullet pattern that goes in a 3D geometric shape
- Maybe because the author felt like it.
- Maybe because it looks cool.
- Maybe because the author thinks the pattern is part of the character.
- Maybe because geometry is sexy.

This is asking like: What's the purpose of riding a bicycle. (Unless I am missing something).

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1703 on: February 26, 2019, 03:21:35 AM »
Sorry for the unfortunate delay... :blush:
Here it is...

Code: [Select]
#include "./functions.dnh"
#include "./shotfunctions.dnh"
#include "./soundfunctions.dnh"

task shoot{
let count = 0;
loop{
if(GetVirtualKeyState(VK_SHOT) != KEY_FREE && count%2 == 0){
if(CanShoot && !IsPlayerSpellActive){
//Regular shots
PlaySoundA1(9, 70, 0);
TShotRegular(GetPlayerX + 8, GetPlayerY, 20, 270, 1, damage*1.5);
TShotRegular(GetPlayerX - 8, GetPlayerY, 20, 270, 1, damage*1.5);
}
}
count++;
yield;
    }
}

task option(rads, rads2, starta, aplus){
let objOption = ObjPrim_Create(OBJ_SPRITE_2D);
Obj_SetRenderPriorityI(objOption, 31);
ObjRender_SetBlendType(objOption, BLEND_ALPHA);
ObjPrim_SetTexture(objOption, GetCurrentScriptDirectory ~ "./....shot.png");
ObjSprite2D_SetSourceRect(objOption, 40, 45, 61, 67);
ObjSprite2D_SetDestCenter(objOption);
ObjRender_SetPosition(objOption, GetPlayerX, GetPlayerY, 0);

let destX;
let destY;
let dist;
let dir;

let a = starta;

let count = 0;
let shotAngle = -90;
while(!Obj_IsDeleted(objOption)){
if(!optionAlive){Obj_Delete(objOption);}
if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_FREE){
destX = GetPlayerX + rads[0]*cos(a);
destY = GetPlayerY + rads[1]*sin(a);
}else{
destX = GetPlayerX + rads2[0]*cos(a);
destY = GetPlayerY - 32 + rads2[1]*sin(a);
}

let opX = ObjRender_GetX(objOption);
let opY = ObjRender_GetY(objOption);
dist = GetDist(opX, opY, destX, destY);
dir = GetAngle(opX, opY, destX, destY);
opX += 0.25 * dist * cos(dir);
opY += 0.25 * dist * sin(dir);
ObjRender_SetPosition(objOption, opX, opY, 0);
ObjRender_SetAngleZ(objOption, count * 2);

if(GetVirtualKeyState(VK_SHOT) != KEY_FREE && count%2 == 0){
if(CanShoot && !IsPlayerSpellActive){
PlaySoundA1(6, 60, 0);
if(GetVirtualKeyState(VK_SLOWMOVE) == KEY_FREE){
TShotRegular(opX, opY, 20, 270, 3, damage*1.5);
TShotRegular(opX, opY, 10, 270, 3, damage*1.5);
}else{
TShotRegular(opX, opY, 20, 270, 3, damage*2.5);
TShotRegular(opX, opY, 20, 270, 3, damage*2.5);
}
}
}
count++;
a += aplus;
yield;
}
}
« Last Edit: February 26, 2019, 03:33:12 AM by Montrek »

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1704 on: February 26, 2019, 07:35:36 AM »
The issue is likely in PlaySoundA1, and likely because you're creating a new sound object every time you want to play something and not deleting it. Problem could also be in TShotRegular but like we said before player shots are deleted automatically by default.

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

Infy♫

  • Demonic★Moe
  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1705 on: February 26, 2019, 11:38:44 AM »
If I am not mistaking, rand() uses the entered parameter as a float and not an integer. What happens under the hood is that if you enter 200 as a parameter, it is actually initialized as 200.000000 by the engine.

If you use rand(200,201) the engine will actually generate a random number between 200.00000 and 201.000000. So technically the randomized number could be 200.583921. So there is no 50% :V Awesome aint it?

To solve this in my own game, I've created my own rand_int() function (which used to exist in 0.12m). It is actually quite dirty because it truncates the decimal value. Pretty sure someone else has a better suggestion to this.
Code: [Select]
// 0.12m personal transition for rand_int.
function rand_int(min,max) {
let rand_int_result;
rand_int_result = truncate(rand(min,max));
return rand_int_result;
}


This is an incorrect operationalization of rand_int. truncate rounds your number down, and statistics dictates that the chance of getting exactly 201 is miniscule. This means rand(200,201) will always return 200, while I figure you want a 50/50 distribution here between 200 and 201.

Here's how I did it:

Code: [Select]
function rand_int(low,high) {
 return truncate(rand(low,high+1));
}

Basically the same as what you did, except the upper bound is increased by 1.

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1706 on: February 26, 2019, 12:35:14 PM »
rand() is inclusive on lower and upper bounds, so you can still technically get 201 there. Anyways, the truncate method screws up if you use negative numbers: with your method rand_int(-1, 0) basically always returns 0, and rand_int(-2, -1) has the same problem of almost never returning -2 while also returning 0 half the time which is very wrong.

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

Infy♫

  • Demonic★Moe
  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1707 on: February 26, 2019, 01:58:04 PM »
rand() is inclusive on lower and upper bounds, so you can still technically get 201 there. Anyways, the truncate method screws up if you use negative numbers: with your method rand_int(-1, 0) basically always returns 0, and rand_int(-2, -1) has the same problem of almost never returning -2 while also returning 0 half the time which is very wrong.
I didn't give the negative number case a thought yet, good point. I suppose what follows now is the better rand_int that I'll be using in my code.

Code: [Select]
function rand_int(low,high){
return round(rand(low-0.49999,high+0.49999));
}
« Last Edit: February 26, 2019, 03:15:35 PM by Infinnacage♫ »

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1708 on: February 26, 2019, 04:35:08 PM »
It seems like the fault was at the enemies all along... :ohdear:
But I don't understand very well, is it bad if I use Jan Aldryn Bio Fairy Functions or is it better if I do my own ???
After all I remember two or three people using this functions other than himself and they worked fine...
edit----------------
Wierd the script it's good all of a sudden... :)
I should still replace the fairies though. :wat:
« Last Edit: February 26, 2019, 05:02:29 PM by Montrek »

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #1709 on: February 27, 2019, 01:50:19 AM »
But I don't understand very well, is it bad if I use Jan Aldryn Bio Fairy Functions or is it better if I do my own ???
After all I remember two or three people using this functions other than himself and they worked fine...

Rule #1 of programming: Don't use code you do not understand

If you use someone else's code, you should use it knowing that it may have undocumented issues. Just because other people use it doesn't mean it works the way you think it does. In particular, afaik those libraries have had other problems here on the Q&A threads before.

It is not a matter of whether or not it is 'better' to make your own version. If that code works for you and you are allowed to use it, by all means feel free to use it. But my overall recommendation is to make your own once you have the experience to do so - you'll have finer-grained control of what your code is doing and it will work the way *you* want it to.

P.S.
https://dmf.shrinemaiden.org/wiki/Script_Functions#SetAutoDeleteObject
https://sparen.github.io/ph3tutorials/ph3u2l16.html
« Last Edit: February 27, 2019, 01:52:37 AM by Sparen »