Welcome, Guest. Please login or register.

What openbor you prefer: Double dragon,battletoads or final fight !? by lirexpatrio
[December 07, 2012, 07:15:27 pm]


what are your favorite games OpenBOR?! by lirexpatrio
[December 07, 2012, 07:09:46 pm]


Post Some Awesome Videos by maxman
[December 07, 2012, 05:51:39 pm]


Can @cmd playmusic "aaaa" 1 also increse music sound ? by BeasTie
[December 07, 2012, 05:24:38 pm]


Streets of Rage: Silent Storm by mtrain
[December 07, 2012, 03:45:05 pm]


Site will be down for maintenance on 12/8/2012 thru 12/10/2012 by Damon Caskey
[December 07, 2012, 07:42:42 am]


Cancelled SOR 3d Remake by riccochet
[December 07, 2012, 03:58:33 am]


Dungeon Fighter: B.O.R. by msmalik681
[December 07, 2012, 03:24:27 am]


[TUTORIAL] How to create 4 Games of OpenBOR in 1 CD (650 MB) by magggas
[December 06, 2012, 09:46:25 pm]


custknife by Bloodbane
[December 06, 2012, 09:34:09 pm]


blockfx help by B.Kardi
[December 06, 2012, 04:09:14 pm]


street of age 4 hd by corradlo
[December 06, 2012, 01:41:36 pm]


ClaFan - Classic Fantasy ver 1.17 by soniczxblade
[December 06, 2012, 05:01:20 am]


Bug Archive by Bloodbane
[December 06, 2012, 02:00:44 am]


"Bio-Doom" and "Gears of Doom" by BulletBob
[December 05, 2012, 10:07:21 pm]


Contra Locked 'N' Loaded v2 by Bloodbane
[December 05, 2012, 09:39:43 pm]


Downloadable OpenBoR Manual by BeasTie
[December 05, 2012, 08:31:24 pm]


Having trouble testing changes by B.Kardi
[December 05, 2012, 03:05:53 pm]


DragonBall Absalon by msmalik681
[December 05, 2012, 02:52:13 pm]


[Hi-Res] Swamp by Vibrant
[December 05, 2012, 10:47:14 am]


  • Dot Guests: 160
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.



Author Topic: Script changes  (Read 495 times)

0 Members and 1 Guest are viewing this topic.

Offline utunnels

  • Developer
  • Hero Member
  • *****
  • Posts: 2713
Script changes
« on: September 09, 2011, 12:23:13 pm »

1. function clear

Just like function main, it is another entry, called when the script is being cleared.
Of course it is optional. The purpose of this function is giving the modder a chance to clear their local variables, which include screen handles, sprite handles and array handles(explain below).

For example:

Code: [Select]
void main(){
    if(getlocalvar("sprite")==NULL())
    {
        setlocalvar("sprite", loadsprite("data/sprites/test.gif"));
    }
    //do something else
}

void clear(){
   if(getlocalvar("localclear")){
      void sprite = getlocalvar("sprite");
      if(sprite!=NULL()){
          free(sprite);
          setlocalvar("sprite", NULL());
      }
    }
}

The only accessible local variable is called "localclear". When it is 0, it means the engine is not about to clear your local variables, so you can do nothing in this case. When it is 1, it means the engine is about to clear your local variables, so you should free the handles before they are gone. When it is 2, it means the engine is about to delete this script, so you should take care of the script variables or they are gone forever.

For entity variables, you should be able to clear them in onkill script.

Important note: Don't do something like killentity (usually you can't since "self" is not accessible, but for those who play with the global variables, it is still dangerous), because kill will raise another clear, and crash the engine.


2. New functions:

array(size);
get(array, index);
set(array, index, value);
size(array);

So you can allocate an array and use it like the indexed variables. Don't forget to free it, and don't forget to free all its subscripted member if necessary (screen, sprite, array, etc).

Example:

Code: [Select]
  int i;
  void a = array(100);
  setglobalvar("my.cool.array", a);

   // blahblah...

   set(a, size(a)-1, "this is the last element");
   set(a, 0, "this is the fisrt element");
   set(a, 3, 123);
   set(a, 4, 99.66);
   set(a, 5, loadsprite("data/chars/dude/001.gif"));
   //blahblah...

    for(i=size(a)-1; i>=0; i--){
       log(get(a, i));
    }
   
    //free the sprite
    free(get(a, 5));
    set(a, 5, NULL());

    // doing this is good for string values
    // there is no array cleaning function so far,
    // so you should NULL them one by one
    for(i=size(a)-1; i>=0; i--){
       set(a, i, NULL());
    }
   
    free(a);
    setglobalvar("my.cool.array", NULL());

    So it is still complex to clean up the array. But since this feature is for the advanced modders, it shouldn't cause too many troubles to novice users.




« Last Edit: December 04, 2011, 01:51:12 am by utunnels »

Offline MatMan

  • Hero Member
  • *****
  • Posts: 1320
Re: Script changes (next release)
« Reply #1 on: September 09, 2011, 12:30:56 pm »
This has many factor of ooooooooohhh!!!

Great add-on utunnels  :cheers!:

Offline Damon Caskey

  • Hero Member
  • *****
  • Posts: 5335
    • The Gorge
Re: Script changes (next release)
« Reply #2 on: September 09, 2011, 12:47:55 pm »
Arrays! That's something I never thought we would see on OpenBOR Script! Nice one UT!  :cheers!:

Assuming you can assign them to indexed vars and not just global vars as in the example, I (and many others) can be rid of slow globals entirely. No more "fakearray.element.a", fakearray.element.b", "...".

DC
« Last Edit: September 09, 2011, 12:54:18 pm by Damon Caskey »
OpenBOR Wiki.

Coming Soon:
Spoiler
Fatal Fury Chronicals


 



 0%




SimplePortal 2.3.3 © 2008-2010, SimplePortal