Jump to content

Photo

Advanced scripting tutorial (WIP)


  • Please log in to reply
44 replies to this topic

#31 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

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

Posted 24 January 2010 - 06:21 PM

QUOTE(Schwa @ Jan 23 2010, 11:11 AM) View Post

I have a question on the subject of user-defined functions.

Would it be possible to assign a set of functions to an array, so a variable can index which one to use? Basically you could check a variable, and run one Function depending on that variable without having to do the If-Then-Else-If method, which I've always thought of as choppy and unrefined. I'd have no idea how to set something like that up, though... Maybe "{variable} = {function name};", like it would trick the variable into setting itself to whatever the function equates to in terms of numerical values (I hope I explained that right icon_heh.gif ).

It's not the end of the world if this can't be done, but if it can, I'll definitely use that over If-Then-Else-If. icon_king.gif


I don't really understand what you mean. You want to call a different function based on a value of an integer?

#32 Saffith

Saffith

    IPv7 user

  • Members

Posted 25 January 2010 - 11:36 AM

Function pointers. No, no way to do that, I'm afraid.

#33 lucas92

lucas92

    Defender

  • Members

Posted 25 January 2010 - 09:35 PM

^That what I was thinking.

Is there any way to implement this, because I think it's a must whenever you have an array. icon_frown.gif

Else you would have to stick all your code in the run() function and your code wouldn't be reusable.

#34 Schwa

Schwa

    Enjoy the Moment more. This strengthens Imagination.

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

Posted 29 January 2010 - 11:04 PM

QUOTE(Saffith @ Jan 25 2010, 08:36 AM) View Post

Function pointers. No, no way to do that, I'm afraid.

I figured that out a couple days ago, but thanks for verifying my suspicions. icon_love.gif

You've all been a tremendous help so far. Thanks everyone. icon_smile.gif I really appreciate every one of you.

#35 Saffith

Saffith

    IPv7 user

  • Members

Posted 10 June 2010 - 12:06 PM

Well, I've neglected these for far too long once again. And probably not for the last time (I'm an expert at not doing stuff). The language has pretty much stabilized now, so I'll try to clean these up in the next few days. Still need to write a section on strings, too... Anyway, just wanted to say I haven't forgotten about these.

#36 Schwa

Schwa

    Enjoy the Moment more. This strengthens Imagination.

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

Posted 11 January 2011 - 03:03 AM

We still love you, Saffie. icon_love.gif Take your time. Get some fresh air though, and spend time with family during your absences. icon_kawaii.gif

I have a simple question, if anyone cares to enlighten me yet again: Does Game->DCounter[] have support with the ten custom Script-based Game Counters we're now given?

If anyone's curious: basically I found the joys of customizing the Subscreen using draw-primitives, and I'm now aiming to add a variety of bar-shaped gauges, that'd work a lot like the Magic Meter only for several different things. These gauges, of course, use the new Script-based Counters, starting with Game->Counter[7], Game->Counter[8], and so forth, and I can save myself a lot of time and code if I can manipulate the Counters via the DrainCounters, rather than having to tack on an extra routine that simulates the same effect.

I'm gonna kill myself with ZScript one day. icon_deformed.gif

#37 Saffith

Saffith

    IPv7 user

  • Members

Posted 11 January 2011 - 09:08 AM

Yes, the script counters work just the same as the others.

#38 SpacemanDan

SpacemanDan

  • Members
  • Location:Ontario, Canada

Posted 09 December 2011 - 01:35 AM

So instead of making a new topic, I'll ask here since we seem to be dealing with arrays here and stuff.

Is it possible to give values to elements of a global array outside of any script or function? For clarification, what I'm doing is making a shop script that relies on arrays to 'align' so that if I put one number in, it can return the tile, price, description and all that fun stuff. The reason I don't just assign these values right away is to keep it organized, since there will be several items in the game you can purchase.

So instead of doing something like this...

CODE
int ITEM_ID[100] = {A hundred numbers here};
int ITEM_NAME[100] = {A hundred strings here};
int ITEM_DESCRIPTION[100] = {A hundred strings here};
int ITEM_TILE[100] = {A hundred numbers here};
int ITEM_PRICE[100] = {A hundred numbers here};


...I can make it easier to read and write by organizing it with something like this:

CODE
ITEM_ID[0] = 5;
ITEM_NAME[0] = "Iron Sowrd";
ITEM_DESCRIPTION[0] = "A simple but versatile weapon";
ITEM_TILE[0] = ICON_SWORD;
ITEM_PRICE[0] = 100;


What I could also do is make a function that does all this fun stuff and have it run at start up or something if this doesn't work.

Also, thank you so much for these tutorials and guides. They've helped tremendously with my ventures into scripting. (Especially arrays. icon_xd.gif)

#39 blue_knight

blue_knight

    Adept

  • Members

Posted 09 December 2011 - 02:37 AM

You can't do single value initialization with arrays, but string initialization is pretty easy:

CODE

int someText[] = "Some text here";


An example use would be:
CODE

int gameOver[] = "Game Over";
Screen->DrawString(6, 127, 0, FONT_Z3, 1, 0, TF_CENTERED, gameOver, 128);


You can also initialize an array and have the number of elements be implied from the initialization:
CODE

int someValues[] = { 1, 2, 3, 4 };


You can do this kind of thing wherever you declare your arrays, just like initializing any variable.

Edited by blue_knight, 09 December 2011 - 02:38 AM.


#40 SpacemanDan

SpacemanDan

  • Members
  • Location:Ontario, Canada

Posted 09 December 2011 - 09:37 AM

Ah, right. I need individual arrays for each of my strings. D: Ah well.

As for the second bit though, I already initialized the array earlier in the script. (I probably should have been more clear on that.) I just want to change the numbers of the elements after having done all the int ARRAY[100] stuff. It'd be outside of any script though. Unless I misunderstand what you're saying, though I do appreciate the help. icon_cat.gif

#41 Saffith

Saffith

    IPv7 user

  • Members

Posted 09 December 2011 - 11:39 AM

You can do this, though:

CODE
int ironSwordName[] = "Iron Sword";
int ironSwordDesc[] = "A simple but versatile weapon";

ITEM_ID[0] = 5;
ITEM_NAME[0] = ironSwordName;
ITEM_DESCRIPTION[0] = ironSwordDesc;
ITEM_TILE[0] = ICON_SWORD;
ITEM_PRICE[0] = 100;


#42 SpacemanDan

SpacemanDan

  • Members
  • Location:Ontario, Canada

Posted 09 December 2011 - 11:24 PM

Ooh, that's handy. icon_biggrin.gif Thanks for the tip! icon_biggrin.gif

#43 Saffith

Saffith

    IPv7 user

  • Members

Posted 18 February 2013 - 12:36 AM

Finally, I've gone through and updated these tutorials. They're fully up-to-date and, unless I've forgotten something, they cover everything that needs covered.

If you're so inclined, look through them and let me know what you think. Here's basic, here's intermediate.

#44 Schwa

Schwa

    Enjoy the Moment more. This strengthens Imagination.

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

Posted 23 February 2013 - 01:11 PM

This is late, but... thanks. icon_smile.gif To this day I still constantly use these to remind myself of how certain features work. It's embarrassing how many times I still forget that for() loops check if the Condition inside is true to keep looping instead of false (I get them mixed up!), and just recently I got my Scrambled Controls effect working correctly and that script used "||=" to combine booleans together, and the tutorials helped walk me through that (again) too.

They're basically the ultimate resource in the entire ZC scene when it comes to scripting. I still can't thank you enough, all this time, for having written them; all of the awesomeness people see in the screenshots and videos I put up of crazy game-engine hijacks, I ought to owe all to you. 'Cause all of that was thanks to these documents, and all I did was take the time to take it to heart and then practice.

Beginners and veterans alike should always keep these documents open in their browser while writing scripts. Take it from Schwa.

#45 Saffith

Saffith

    IPv7 user

  • Members

Posted 26 February 2013 - 10:56 AM

Good to hear. Glad they've been useful.


The plan is still to post these in the tutorial forum eventually. I'll wait a while longer for feedback, maybe revise them a little more, but I think they're basically done at this point.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users