Jump to content

Photo

"Half-dead" Script


  • Please log in to reply
15 replies to this topic

#1 Isdrakthül

Isdrakthül

    Apprentice

  • Members

Posted 31 December 2010 - 12:10 PM

Recently, I decided that, while I will continue to make quests in 2.10 to learn the basics of ZQuest, I would like to try to script. I downloaded 2.50 and looked over the ZC wiki's pages about scripting, then attempted to write a script that makes Link stumble around when his health is low to get some practice. Unsurprisingly, it did not work and I don't know how to fix it.

CODE

global script Halfdead
{
    void run() {
    }
        if(Link->HP <= 16 ){
          Link->Drunk
        }
}


Could someone fix this so that I can see what I did wrong? Any help would be appreciated.

#2 Banjo7J

Banjo7J

    Defender

  • Members
  • Real Name:John
  • Location:Scotland

Posted 31 December 2010 - 12:41 PM

I believe it's the first } after void run(). Move that so that it's the 2nd last of it's kind and it should work. In other words, you need to make it this:

CODE
global script Halfdead
{
    void run() {
        if(Link->HP <= 16 ){
            Link->Drunk
        }
    }
}


I also added propers tabs instead of a bunch of spaces to make it neater but that's optional.

#3 Isdrakthül

Isdrakthül

    Apprentice

  • Members

Posted 31 December 2010 - 01:01 PM

It's still not working for some reason. When I try to import it, it says
QUOTE
Unable to parse instruction 1 from Halfdead.txt
The error was: invalid instruction!
The command was (script) (Halfdead,)


I get the feeling that I'm missing some blindingly obvious formatting thing or something, but I have no idea what it is.

#4 Banjo7J

Banjo7J

    Defender

  • Members
  • Real Name:John
  • Location:Scotland

Posted 31 December 2010 - 01:08 PM

Weird, I've never seen an error like that before. Beats me.

#5 MarioBrosCom

MarioBrosCom

    Adept

  • Members
  • Real Name:Stylianos
  • Location:Canada

Posted 31 December 2010 - 01:22 PM

Global scripts are run only once, so you need to move everything in your script into a while loop that repeats every frame.

CODE
global script slot2 {
    void run() {
        while (true) {
            // Your script here.
            Waitframe();
        }
    }
}

You need to include the Waitframe at the end of your script or else the game will freeze.

You're getting compile errors because you're missing a semicolon after Link->Drunk. Also, you have to set the number of frames you want Link to be drunk, so you'll want something like Link->Drunk = 1;.

#6 Isdrakthül

Isdrakthül

    Apprentice

  • Members

Posted 31 December 2010 - 01:31 PM

So, the final code would be as follows, right?

CODE

global script Halfdead {
    void run() {
        while (true) {
            if(Link->HP <= 16 ){
          Link->Drunk = 1;
        }
            Waitframe();
        }
    }
}


EDIT: That didn't work. It says:

QUOTE

Unable to parse instruction 1 from Halfdead.txt
The error was: invalid instruction!
The command was (script) (Halfdead,{)


What would the final code be?

Edited by Isdrakthül, 31 December 2010 - 01:40 PM.


#7 Plissken

Plissken

    What's with these homies dissing our girls?

  • Members

Posted 31 December 2010 - 01:50 PM

That's cause you're trying to import your zscript script as a ZASM script. Please read the tutorial I wrote up on importing scripts:

http://www.purezc.co...showtopic=38376

#8 Isdrakthül

Isdrakthül

    Apprentice

  • Members

Posted 31 December 2010 - 02:33 PM

Well, I managed to import it, but it doesn't do anything. Any ideas?

#9 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 31 December 2010 - 03:03 PM

Did you assign it to a script slot?

#10 Isdrakthül

Isdrakthül

    Apprentice

  • Members

Posted 31 December 2010 - 03:04 PM

Yes. I used the Active slot.

#11 Jared

Jared

    Deified

  • Members
  • Real Name:Jared
  • Pronouns:He / Him
  • Location:New Hampshire

Posted 31 December 2010 - 03:42 PM

What does it technically do, while he "stumbles"? Does he walk slower, slop sometimes or something? icon_smile.gif

#12 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 31 December 2010 - 03:46 PM

Try changing the if hp<16 to while. It's just a thought.

#13 Isdrakthül

Isdrakthül

    Apprentice

  • Members

Posted 31 December 2010 - 04:06 PM

Well, it's now freezing the game when my hearts go to one.

CODE

import "std.zh"

global script Halfdead {
    void run() {
        while (true) {
            while(Link->HP <= 16 ){
          Link->Drunk = 1;
        Waitframe();
        }
            Waitframe();
        }
    }
}


Thoughts?

Edited by Isdrakthül, 31 December 2010 - 04:11 PM.


#14 MarioBrosCom

MarioBrosCom

    Adept

  • Members
  • Real Name:Stylianos
  • Location:Canada

Posted 31 December 2010 - 04:41 PM

You shouldn't have to use another while loop: the original while loop should keep resetting Link's drunk timer if his health is still too low. See if setting Link->Drunk to 2 or some other higher number has any effect.

I don't see any reason why adding that extra while loop would freeze the game, though.

#15 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 31 December 2010 - 04:49 PM

I forget how Drunk works (or if it works) , so try this:

CODE

bool FrameLoop(){ Waitframe(); return true; }

global script Halfdead
{
    void run()
  {
  int t;
        while ( FrameLoop() )
    {
    if(Link->PressR) t++;
          Link->Drunk = t;
    }

    }
}



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users