~Hakurei Shrine~ > Rika and Nitori's Garage Experiments

※ Danmakufu Q&A/Problem thread 3 ※

Pages: << < (360/366) > >>

PyuDi:


--- Code: ---if (frame%60==0)
{
   let obj = ShotA(1); //ShotA is any createshot
}
ObjMove_SetX(obj, 0); //error: obj is not defined

--- End code ---

And this throws an error. How can I use an variable out of its {}?

Helepolis:


--- Quote from: PyuDi on July 06, 2019, 07:54:47 AM ---
--- Code: ---if (frame%60==0)
{
   let obj = ShotA(1); //ShotA is any createshot
}
ObjMove_SetX(obj, 0); //error: obj is not defined

--- End code ---

And this throws an error. How can I use an variable out of its {}?

--- End quote ---
Please post code along with the error because we don't know how you exactly programmed this.

I assume this is inside the @MainLoop? Then you should define the variable globally.

PyuDi:

code: https://pastebin.com/Yx1NdbdJ (look for  if (frame%30==0) )

-> How can I use an variable out of its declared {}?

Sparen:


--- Quote from: PyuDi on July 06, 2019, 08:38:56 AM ---code: https://pastebin.com/Yx1NdbdJ (look for  if (frame%30==0) )

-> How can I use an variable out of its declared {}?

--- End quote ---

Your code is as follows:

--- Code: ---    loop(8)
            {
                let obj = CreateShotA1(rand(0,fx), 0, rand(1,3), 90+rand(-5,5), DS_BALL_BS_GREEN, 20);
            }
            ObjMove_SetAngle(obj, -90);  // obj is not defined
--- End code ---
Your aim is to create eight objects and then set their angle immediately. Therefore, you can do the following:

--- Code: ---    loop(8)
            {
                let obj = CreateShotA1(rand(0,fx), 0, rand(1,3), 90+rand(-5,5), DS_BALL_BS_GREEN, 20);
                ObjMove_SetAngle(obj, -90);  // obj is not defined
            }
           
--- End code ---

Understanding scoping rules is important, but understanding why they exist is also important. I'd take a look at your old code and think about why what you originally wrote would cause problems IF the variables could be accessed from outside of the block. For example, how many of the objects would actually have their speed set?

Lapis Lazuli:

EDIT: never mind, I found out how to make this work! still, thank you!

heya!!
So uhm, I've been trying to make a danmakufu script and I wanted to make an attack that creates cheeto lasers (you know, the kind of homing curvy laser that Shinki used in her boss fight that made her infamous?). However, I can't get the algorithm that decides whether or not the laser should turn left or right to work properly, and it often flees from the player instead of chasing them like you'd expect. I've looked into a bunch of other scripts that use cheeto lasers (such as a lot of stuff from SCC, or some of Kiyohime's attacks in RSS) and, frankly, I can't parse them. Can someone else help me?

Here's the code and a .gif of a laser that spawned in the middle of the screen, so you can get a good idea of what I'm trying to do. (be warned, it's kind of messy)


--- Code: ---task summonWolf(wx, wy)
{
    let wa = atan2(GetPlayerY - wy, GetPlayerX - wx);
    let ws = 6;
   
    let wolf = CreateCurveLaserA1(wx, wy, ws, wa, 60, 30, DS_SCALE_WHITE, 0);
    let wolf2 = CreateCurveLaserA1(wx, wy, ws, wa, 60, 30, DS_NEEDLE_WHITE, 0);
    ObjCrLaser_SetTipDecrement(wolf, 0);
    ObjCrLaser_SetTipDecrement(wolf2, 0);
    let accel = 0.07;
    let wvelo = 2;
    ascent (i in 0..10)
    {
        ObjMove_AddPatternA2(wolf, 0 + 120 * i, NO_CHANGE, NO_CHANGE, -accel, 0, -1000);
        ObjMove_AddPatternA2(wolf2, 0 + 120 * i, NO_CHANGE, NO_CHANGE, -accel, 0, -1000);
        ObjMove_AddPatternA2(wolf, 60 + 120 * i, NO_CHANGE, NO_CHANGE, accel, 0, 1000);
        ObjMove_AddPatternA2(wolf2, 60 + 120 * i, NO_CHANGE, NO_CHANGE, accel, 0, 1000);
    }
    //let objText = ObjText_Create();
    //ObjText_SetText(objText, "--> Russell Square Regular <--");
    loop(720)
    {
        let lx = ObjMove_GetX(wolf);
        let ly = ObjMove_GetY(wolf);
        let la = ObjMove_GetAngle(wolf) % 360;
        let la2 = atan2(GetPlayerY - ly, GetPlayerX - lx);
        //ObjText_SetText(objText, la2 - la);
       
        if (la < la2)
        {
            ObjMove_SetAngularVelocity(wolf, wvelo);
            ObjMove_SetAngularVelocity(wolf2, wvelo);
        }
        else
        {
            ObjMove_SetAngularVelocity(wolf, -wvelo);
            ObjMove_SetAngularVelocity(wolf2, -wvelo);
        }
       
        yield;
    }
}
--- End code ---

https://cdn.discordapp.com/attachments/436365025339506720/605173240574509077/danmakufu.gif (im sorry, i haven't figured out how to attach it directly as an image! let me know if youre not able to view the link)

thank you!!  :D

Pages: << < (360/366) > >>

Go to full version