Jump to content

Photo

Error help on building symbol tables


  • Please log in to reply
24 replies to this topic

#1 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 18 October 2016 - 10:12 PM

can someone tell me why ZC is saying 

"Error T37: Global Variables can only be initialized to constants or globals declared in the same script"

//Init Variables

//Movement Speed 
int prevX = Link->X;
int prevY = Link->Y;

//Update function call this in your global active script
void LinkUpdate()
{
	if (!LinkJump) { LinkSpeed(2.5); }
}

int LinkJump() {
	int jmp = Floor(Link->Jump); //Floor Link->Jump to ensure that a value of 0.050 is '0'.
	return jmp; //Return the floored value.
}

int LinkSpeed(int speed) {
	
	//Snap Link to previus position before custom movement
	if (Link->X != prevX) { Link->X = prevX; }
	if (Link->Y != prevY) { Link->Y = prevY; }
	
    //Up
    if( Link->InputUp
    && !Screen->isSolid(Link->X,Link->Y+6) //NW
    && !Screen->isSolid(Link->X+7,Link->Y+6) //N
    && !Screen->isSolid(Link->X+15,Link->Y+6) //NE
    )
        Link->Y -= speed;
    //Down
    else if( Link->InputDown
    && !Screen->isSolid(Link->X,Link->Y+17) //SW
    && !Screen->isSolid(Link->X+7,Link->Y+17) //S
    && !Screen->isSolid(Link->X+15,Link->Y+17) //SE
    )
        Link->Y += speed;
    //Left
    else if( Link->InputLeft
    && !Screen->isSolid(Link->X-2,Link->Y+8) //NW
    && !Screen->isSolid(Link->X-2,Link->Y+15) //SW
    )
        Link->X -= speed;
    //Right
    else if( Link->InputRight
    && !Screen->isSolid(Link->X+17,Link->Y+8) //NE
    && !Screen->isSolid(Link->X+17,Link->Y+15) //SE
    )
        Link->X += speed;
		
	int prevX = Link->X;
	int prevY = Link->y;
}

this is build off of someone else's code



#2 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 18 October 2016 - 11:03 PM

It is what is sounds like.

int prevX = Link->X;
int prevY = Link->Y;
These can't be initialized to those values. Do this instead.

int prevX;
int prevY;
Then set their values inside the global active script if you have to.

#3 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 18 October 2016 - 11:15 PM

@Lejes I'm using this script as a a extension script

so basically the global script is in another file calling from this script



#4 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 18 October 2016 - 11:31 PM

That doesn't seem like it has any relevance? Importing a file containing this should be the same as just manually appending it to the original file.

#5 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 19 October 2016 - 12:47 AM

ok thanks

but my new version has bugs can you direct me towards the problems?

1) link seems to move left and up faster then right and down

2) link right now seems to move up when I press down

3) collision code is not perfect actually its very bad. I was trying to make it more directional based


//Define Movement Speed Variables
int CenterX;
int CenterY;
int prevX;
int prevY;
float DirX;
float DirY;

void LinkInit()
{
    //Init Movement Speed Variables
    prevX = Link->X;
    prevY = Link->Y; 
}

void LinkUpdate()
{
    //Update Movement Speed
	if (!LinkJump()) { LinkSpeed(2.5); }
}

int LinkJump() {
	int jmp = Floor(Link->Jump); //Floor Link->Jump to ensure that a value of 0.050 is '0'.
	return jmp; //Return the floored value.
}

bool LinkCollisionSolid(int x, int y)
{
    CenterX = Link->X+8;
    CenterY = Link->Y+8;
    
    if (x != 0
    && Screen->isSolid(CenterX-8,CenterY+(8*y))
    && Screen->isSolid(CenterX,  CenterY+(8*y))
    && Screen->isSolid(CenterX+8,CenterY+(8*y))
    )
        return true;
    
    if (y != 0
    && Screen->isSolid(CenterX+(8*x),CenterY-8)
    && Screen->isSolid(CenterX+(8*x),CenterY  )
    && Screen->isSolid(CenterX+(8*x),CenterY+8)
    )
        return true;
    
    return false;
}

int LinkSpeed(float speed) {
	
    if (!LinkCollisionSolid( 0, -1 )) {
        if (Link->InputDown || Link->PressDown) {
            Link->Y -= speed;
        }
    }
    else if (!LinkCollisionSolid( 0,  1 )) {
        if (Link->InputUp || Link->PressUp) {
            Link->Y += speed;
        }
    }
    if (!LinkCollisionSolid( -1,  0 )) {
        if (Link->InputLeft || Link->PressLeft) {
            Link->X -= speed;
        }
    }
    else if (!LinkCollisionSolid(  1,  0 )) {
        if (Link->InputRight || Link->PressRight) {
            Link->X += speed;
        }
    }
    //Update Link's Previous X and Y 
	prevX = Link->X;
	prevY = Link->Y;
}


#6 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 19 October 2016 - 12:59 AM

Link->X and Link->Y are truncated. That means they can't hold values after the decimal point. If Link->X is 100, and you set it to 99.99, it becomes 99. If you set it to 100.01, it stays 100. I think you can see why this makes Link move up/left, but not down/right. Since X and Y can't retain small values like what you're trying to add to them, you have to use an intermediate variable that can.
 
storedLinkX += speed;
Link->X = Round(storedLinkX);
You still have to be careful with this approach. If Link->X and storedLinkX ever get out of sync, Link will teleport to his new location. You need to write your code appropriately so this doesn't happen.

As for Link moving down when you press up, that's because you have your Y axis flipped. ZC considers down positive on the Y axis.

Your collision code...I would recommend trying to integrate CanWalk() from std.zh here. Solidity checks are hard to get right in general. Even CanWalk() isn't perfect, but it should more or less do what you need it to here.

Edited by Lejes, 19 October 2016 - 01:00 AM.


#7 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 19 October 2016 - 01:21 PM

what is the step parameter in the canwalk function?

also the parameter full tile says it should be true if I don't want the upper eight pixels to overlap.

does that mean I need to check if links y is lesser then the screens height?



#8 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 19 October 2016 - 04:57 PM

Lejes

​Edit2: Link is not detecting collisions properly

he keeps getting stuck in the air and not being able to move also he is able to pass though some things

 

also I don't know what to check for to reset his X and Y variables

screen change is one I guess but idk if there are others and how to check for them


Edited by Shadowblitz16, 19 October 2016 - 05:37 PM.


#9 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 19 October 2016 - 06:54 PM

Post your code as it is now.

#10 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 19 October 2016 - 07:16 PM

Lejes

 

right now he can't stab the wall and he is having some weird direction issues

also he can't interact with chests.

 

I need to know what type of things to check for to make this script 100% flawless

 

 

Edit: I stopped using the collision code inside the Speed function because it was the one that was buggy

Edit2: I updated the script


 
//Define Movement Speed Variables
float X;
float Y;
float prevX;
float prevY;
float DirX;
float DirY;
 
void LinkInit()
{
    //Init Movement Speed Variables
    X = Link->X;
    Y = Link->Y;
    prevX = Link->X;
    prevY = Link->Y; 
 
}
 
void LinkUpdate()
{
    //Update Movement Speed
if (!LinkJump()) { LinkSpeed(1.0); }
}
 
int LinkJump() {
int jmp = Floor(Link->Jump); //Floor Link->Jump to ensure that a value of 0.050 is '0'.
return jmp; //Return the floored value.
}
 
bool LinkCollisionSolid(int x, int y, int dir, float speed, bool checkDiagonal)
{
    
    if (checkDiagonal) 
    {   
        if (dir == 0 || 1)
        if (!CanWalk(x-16, y, dir, speed, true)) 
        if (!CanWalk(x   , y, dir, speed, true))
        if (!CanWalk(x+16, y, dir, speed, true))
            return true;
            
        if (dir == 2 || 3)
        if (!CanWalk(x, y-16, dir, speed, true)) 
        if (!CanWalk(x, y,    dir, speed, true))
        if (!CanWalk(x, y+16, dir, speed, true))
            return true;
    }
    else 
    {
        if (!CanWalk(x, y, dir, speed, true))
        {
            return true; 
        }
    }
    return false;
}
 
int LinkSpeed(float speed) {
    
    
    //Set Link's X and Y to the previus versions
    Link->X = prevX;
    Link->Y = prevY;
 
    if (Link->Action == LA_WALKING) {
        //Up
        if( Link->InputUp
        && !Screen->isSolid(X,Y+6) //NW
        && !Screen->isSolid(X+7,Y+6) //N
        && !Screen->isSolid(X+15,Y+6) //NE
        )
        {
            Y -= speed;
            Link->Y = Y;
        }
            
        //Down
        else if( Link->InputDown
        && !Screen->isSolid(X,Y+17) //SW
        && !Screen->isSolid(X+7,Y+17) //S
        && !Screen->isSolid(X+15,Y+17) //SE
        )
        {
            Y += speed;
            Link->Y = Y;
        }
            
        //Left
        else if( Link->InputLeft
        && !Screen->isSolid(X-2,Y+8) //NW
        && !Screen->isSolid(X-2,Y+15) //SW
        )
        {
            X -= speed;
            Link->X = X;
            
        }
            
        //Right
        else if( Link->InputRight
        && !Screen->isSolid(X+17,Y+8) //NE
        && !Screen->isSolid(X+17,Y+15) //SE
        )
        {
            X += speed;
            Link->X = X;
            
        }
    }
 
    //Update Link's Previous X and Y 
prevX = Link->X;
prevY = Link->Y;
}

Edited by Shadowblitz16, 19 October 2016 - 07:32 PM.


#11 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 19 October 2016 - 07:39 PM

A couple things I'm noticing: first, you only need to call CanWalk() once for any given direction. It already contains the three checks for solidity inside itself, you don't need to reproduce them. Second, step is speed, in pixels per frame. Link's default walk speed is 1.5, so calling LinkSpeed(1.0) will make him go slower, once the function is fixed. If that's what you want.

#12 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 19 October 2016 - 09:04 PM

Lejes 

ok so I made it only call CanMove() once however I can't seem to get it to work right

 

right now I think it is the step parameter. should I pass in the floored value of my speed variable?

 

also is there a way to check if the screen has changed or scrolled?

I need this because I need to set my X and Y variable afterwords so that link doesn't get desynced

 

 
//Define Movement Speed Variables
float X;
float Y;
float prevX;
float prevY;
int Dir;
int prevDir;
 
void LinkInit()
{
    //Init Movement Speed Variables
    X = Link->X;
    Y = Link->Y;
    prevX = Link->X;
    prevY = Link->Y; 
    Dir = Link->Dir;
    prevDir = Link->Dir;
 
}
 
void LinkUpdate()
{
    //Update Movement Speed
if (!LinkJump()) { LinkMove(1.0); }
}
 
int LinkJump() {
int jmp = Floor(Link->Jump); //Floor Link->Jump to ensure that a value of 0.050 is '0'.
return jmp; //Return the floored value.
}
 
int LinkMove(float speed) 
{
    //Set Link's X and Y to the previus versions
    Link->X = prevX;
    Link->Y = prevY;
    
    //Set Dir var to Link's Dir
    Dir = Link->Dir;
 
    //IF Link is walking and there is no collision move link in desired direction
    if (Link->Action == LA_WALKING) 
    {
        if (CanWalk(X, Y, Dir, Round(speed), true))
        {
            //Vertical
            if (Link->InputUp || Link->PressUp)
            { 
                Y -= speed;
                Link->Y = Y;          
            }
            else if (Link->InputDown || Link->PressDown)
            { 
                Y += speed;
                Link->Y = Y;          
            }
            
            //Horizontal
            if (Link->InputLeft || Link->PressLeft)
            { 
                X -= speed;
                Link->X = X;          
            }
            else if (Link->InputRight || Link->PressRight)
            { 
                X += speed;
                Link->X = X;          
            }
        }
    }
 
    //Update Link's Previous X and Y 
prevX = Link->X;
prevY = Link->Y;
    prevDir = Link->Dir;
}


#13 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 19 October 2016 - 09:37 PM

You can have your global script look at Game->GetCurScreen() and Game->GetCurDMap(). If either one of those changes from what it was last frame, you know the screen changed and you can force update the X and Y tracking variables.

#14 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 19 October 2016 - 11:55 PM

Making Link walk more slowly was a lot harder than I thought it would be. Using the position altering approach that works for speed increases didn't go so well. Maybe I missed something, but it seems like you have to go with an input damping approach for the slow walk instead?

Link Speed Global Function


#15 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 20 October 2016 - 11:58 AM

@lejes

ya I got it working somewhat but I was going to make a LA Link State machine so that I could recode in Link's actions and animations

 

something like this...

//import "LinkUtilities.zh"
 
 
//Define Screen Variables
int screen;
int prevScreen;
 
int dMap;
int prevDMap;
 
//Define Movement Speed Variables
float x;
float y;
int dir;
float prevX;
float prevY;
int prevDir;
 
//Define Config Variables
float walkUpSpeed;
float walkDownSpeed;
float walkLeftSpeed;
float walkRightSpeed;
 
//Define Flags
bool linkCanWalk;
bool linkCanDirect;
bool linkCanAttack;
bool linkCanSwim;
bool linkCanJump;
//////////////////////////////////////////////////////////////////////////
//Event Scripts Run these in your global scripts
//////////////////////////////////////////////////////////////////////////
void LinkInit()
{
    //Init Movement Speed Variables
    x         = Link->X;
    y         = Link->Y;
    dir       = Link->Dir;
    prevX     = Link->X;
    prevY     = Link->Y; 
    prevDir   = Link->Dir;
    
    //Init Config
    walkUpSpeed = 1.0;
    walkDownSpeed = 1.0;
    walkLeftSpeed = 1.0;
    walkRightSpeed = 1.0;
    
    //Init Flags
    linkCanWalk   = false;
    linkCanDirect = false;
    linkCanAttack = false;
    linkCanSwim   = false;
    linkCanJump   = false;
 
}
 
void LinkUpdate()
{
    if (linkCanWalk)   { LinkWalk( walkUpSpeed, walkDownSpeed, walkLeftSpeed, walkRightSpeed); }
    if (linkCanDirect) { LinkDirect(); }
    if (linkCanAttack) { }
    if (linkCanSwim)   { }
    if (linkCanJump)   { }  
    UpdateCurrentVars(); 
    LinkSwitchStates();
    UpdatePreviousVars();
}
 
void UpdateCurrentVars()
{
    screen = Game->GetCurScreen();
    dMap = Game->GetCurDMap();
}
 
void UpdatePreviousVars()
{
    prevScreen = Game->GetCurScreen();
    prevDMap = Game->GetCurDMap();
    
    prevX   = Link->X;
    prevY   = Link->Y;
    prevDir = Link->Dir;
}
 
//////////////////////////////////////////////////////////////////////////
//Main state script run this in LinkUpdate()
//////////////////////////////////////////////////////////////////////////
void LinkSwitchStates()
{
    //Update States
    if (Link->Action == LA_NONE)
    {
        linkCanWalk    = true;
        linkCanDirect  = true;
        linkCanAttack  = true;
        LinkNone();
    }
    else if (Link->Action == LA_WALKING)
    {
        linkCanWalk    = true;
        linkCanDirect  = true;
        linkCanAttack  = true;
        LinkWalk();
    }
    else if (Link->Action == LA_ATTACKING)
    {
        linkCanWalk    = false;
        linkCanDirect  = false;
        linkCanAttack  = true;
        LinkAttack();
    }
    else if (Link->Action == LA_CHARGING)
    {
       linkCanWalk     = true;
       linkCanDirect   = false;
       linkCanAttack   = false;
       LinkCharge(); 
    }
    else if (Link->Action == LA_SPINNING)
    {
       linkCanWalk     = false;
       linkCanDirect   = true;
       linkCanAttack   = true;
       LinkSpin();         
    }
    else if (screen != prevScreen) //The Screen has changed
    {
        linkCanWalk    = true;
        linkCanDirect  = true;
        linkCanAttack  = false;
        LinkScreen();
    }
    else if (dMap != prevDMap) //The Dmap has changed
    {
        linkCanWalk    = true;
        linkCanDirect  = true;
        linkCanAttack  = false;
        LinkDMap();        
    }
}
 
//////////////////////////////////////////////////////////////////////////
//State scripts
//////////////////////////////////////////////////////////////////////////
void LinkNone()
{
    
}
 
void LinkIdle()
{
    
}
 
void LinkWalk()
{
}
 
void LinkSwing1()
{
}
 
void LinkSwing2()
{
    
}
 
void LinkCharge()
{
    
}
 
void LinkStab()
{
    
}
 
void LinkSpin()
{
    
}
 
void LinkDrown()
{
    
}
 
void LinkDive()
{
    
}
 
void LinkFall()
{
    
}
 
void LinkJump() 
{
 
}
 
void LinkHurt()
{
    
}
 
void LinkDying()
{
    
}
 
void LinkScreen()
{
    LinkResetPos();
}
 
void LinkDMap()
{
    LinkResetPos();
}
 
 
//////////////////////////////////////////////////////////////////////////
//Flag Scripts
//////////////////////////////////////////////////////////////////////////
void LinkWalk(float uSpeed, float dSpeed, float lSpeed, float rSpeed) 
{
    //Set Speed Variable
    int Speed;
    
    //Set Link's x and y to the previus versions
    Link->X = prevX;
    Link->Y = prevY;
    
    //Switch Speed variable
    if      (dir == 0) { Speed = uSpeed; }
    else if (dir == 1) { Speed = dSpeed; }
    else if (dir == 2) { Speed = lSpeed; }
    else if (dir == 3) { Speed = rSpeed; }
    
    //IF there is no collision move link in desired direction
    if (CanWalk(x, y, dir, Round(Speed), false))
    {
        if (Link->InputUp || Link->PressUp)
        { 
            y -= Speed;
            Link->Y = Round(y);      
        }
        else if (Link->InputDown || Link->PressDown)
        { 
            y += Speed;  
            Link->Y = Round(y);        
        }
             
        if (Link->InputLeft || Link->PressLeft)
        { 
            x -= Speed;  
            Link->X = Round(x);      
        }  
        else if (Link->InputRight || Link->PressRight)
        { 
            x += Speed;
            Link->X = Round(x);   
        }
    }
}
 
void LinkDirect()
{
    Link->Dir = prevDir; 
    if (Link->Dir != dir)
    {
        Link->Dir = dir;
    }
}
 



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users