Jump to content

Photo

Basic scripting tutorial (WIP)


  • Please log in to reply
66 replies to this topic

#46 Saffith

Saffith

    IPv7 user

  • Members

Posted 04 December 2008 - 12:58 PM

The simplest way would be Link->Item[item]=true. If you want him to hold it up, though, that's a bit tougher. I'm pretty sure using CreateItem() and moving it to Link's position would work, but I don't think you can do that while the screen's frozen.

#47 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 04 December 2008 - 01:11 PM

What if i ditch the part of freezing the screen and have all of link's actions false,give him the item and the re enable links action again? You should really add in this tutorial on how every link pointer works. Even though thats in zscript.txt

#48 Joe123

Joe123

    Retired

  • Members

Posted 04 December 2008 - 01:40 PM

Why should you not be able to do it while the screen's frozen?
I'm pretty sure you can.

#49 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 05 December 2008 - 12:52 PM

Maybe because im freezing the screen . But thinking about it would seem awkward having the screen frozen. So ill just disable all of links action untill he receives the item.

#50 Schwa

Schwa

    Enjoy the Moment more. This strengthens Imagination.

  • Members
  • Real Name:Hunter S.
  • Location:Redmond Subspace (I had a Potion)

Posted 13 January 2010 - 07:50 AM

I'm seriously wracking my brain over this bit here... Scratch that. My skull is being ripped apart with diamond-crafted hooks.

QUOTE
You'll notice that many variables have a note that "The effects of writing to this variable are undefined." These are meant to be read-only; you shouldn't try to change them. Assigning new values to these variables may not work as expected, and even if it does, it's not guaranteed to work on every platform or in later versions.


I've seen this technique imployed in various scripts, one example being the Straffe Script; it's a script where Link can walk in all directions while facing one set direction the whole time as long as you hold the L Button. To achieve this, it writes to "Link->Dir", which is labeled "read-only" as you stated.

During all my latest scripting endeavors I've been desperately wanting to mess with some of these untouchable variables, and have been frustrated that they were off-limits. Then later I came across this Straffe Script, freaked out, looked this up for clarification, and now I want to cry.

Are you telling me that any of these read-only variables MIGHT be changeable but it's nothing but one big ridiculous gamble, in that it might change later or might not and there's no way to know?

...That's really unfair. I want to cry. I'm afraid to script now.

Edited by Schwa, 13 January 2010 - 07:53 AM.


#51 Joe123

Joe123

    Retired

  • Members

Posted 13 January 2010 - 08:04 AM

Basically what that means is 'you can use them, but don't take it for granted that they will always work how they do at the moment'.
Setting Dir shouldn't really have that written after it in ZScript.txt in my opinion because it's something that everyone uses.

#52 Schwa

Schwa

    Enjoy the Moment more. This strengthens Imagination.

  • Members
  • Real Name:Hunter S.
  • Location:Redmond Subspace (I had a Potion)

Posted 13 January 2010 - 08:59 AM

Ah alright. I think most of my fear was just the initial shock. At the very worst, I could just re-write something if it became broken, and from what I've seen _L_ is a pretty reasonable guy and has made accommodations for community members in the past... ^^ Nothing to worry about! Thanks brah.

#53 Schwa

Schwa

    Enjoy the Moment more. This strengthens Imagination.

  • Members
  • Real Name:Hunter S.
  • Location:Redmond Subspace (I had a Potion)

Posted 11 February 2010 - 07:20 AM

Alright, I want to make sure I'm doing this right. Take a look.

CODE
Link->InputUp & (FrameCount % 2);


...where "FrameCount" is a variable that is incremented once per frame. The object is to halve the speed of Link's movement by disabling the four arrow keys every other frame (meaning I apply this to InputDown, Left and Right as well). I haven't tested it yet, as I'm setting up a couple different scripts at once, but do you guys think this will work? I don't think I ever used Bitwise AND or the Modulus operator once yet, and it's kinda hilarious that I'm now using both at the same time. icon_xd.gif It looks like it'd work though!

Keep in mind too that Link->InputUp is a boolean. Just reminding people.

#54 Joe123

Joe123

    Retired

  • Members

Posted 11 February 2010 - 07:32 AM

Yeah, you'll get a 'Cannot cast from bool to float' error on that one.

CODE
if(Link->InputUp && FrameCounter%2) Link->InputUp = false;


Thinking about it, that's a much better way than how I had been doing it previously. I shall update my code.

#55 Cameron

Cameron

    Illustrious

  • Members
  • Real Name:Matt
  • Location:South Jersey

Posted 17 February 2010 - 03:30 PM

Why did it take me so long to find this!? This is absolutely perfect. Thanks! icon_awesome.gif

#56 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 17 February 2011 - 02:20 AM

I'm sure that it is perfectly reasonable to bump this topic for this: Right now, I am making a Purple Chu Potion script, and I want to install a section that freezes the screen while it damages/heals Link, very much like what the built-in potions do. How do you do that without setting a Screen Freeze Combo on the screen while it does that (if the player F6s while it is in action, there WILL be troble if I use the Screen Freeze Combo method).

#57 TheLegend_njf

TheLegend_njf

    Deified

  • Members
  • Real Name:Grant

Posted 09 April 2014 - 07:17 PM

This topic is wonderful, I was always intimidated by scripts until I read this topic.

Also, I am reading it over and over just so I can absorb all the material. I highly recommend this topic to anybody who knows how to add scripts to their quest but is not entirely sure what it is that they are adding.

#58 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 10 April 2014 - 10:11 AM

Good to hear your feeling less intimidated now, If there's anything you don't understand feel free too ask in this topic or my AMA topic. The link is in my signature.



#59 SyrianBallaS

SyrianBallaS

    Defender

  • Members
  • Real Name:Samer
  • Location:Detroit, Michigan

Posted 12 June 2014 - 12:29 PM

zscripting seems pretty cool, it's like a mix of C and Java. Is the run() function simialar to main()


Edited by GhostKnight22, 12 June 2014 - 12:32 PM.


#60 Frocks7Snee

Frocks7Snee

    Illustrious

  • Members

Posted 15 June 2014 - 08:45 AM

Here's how you would use this made-up function.

// All the function does is add two numbers, so it's equivalent to ordinary addition.
// You assign the return value to a variable the same way as anything else.
this->X = Add(5, 11); // Equivalent to this->X = 5 + 11;
Link->HP = Add(48, -16); // Equivalent to Link->X = 48 + -16;
Add(10, 25) = this->Y; // ERROR: You can't assign a value to a function
Link->HP = Add(4, 12, 8); // ERROR: The function takes exactly two arguments; you can't use more or fewer, even if it seems logical

There's a small error in the functions section you might want to fix so that it won't confuse people. The function in question is Link->HP = Add(48,-16) but you describe it as "Equivalent to Link->X = 48 + -16"

 

EDIT: My bad, didn't see how old this was.  :awesome:


Edited by Rocks4Free, 15 June 2014 - 08:59 AM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users