Jump to content

Photo

ALTTP Torches Lighting Room.


  • Please log in to reply
42 replies to this topic

#16 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 02 March 2016 - 12:42 PM

Way ahead of you there on that one lol I've been assigning it each time I test.

Edit:

Well, it doesn't throw any errors, but upon entering the darkened room, it freezes the game, and, unfortunately, the computer as well.



#17 grayswandir

grayswandir

    semi-genius

  • ZC Developers

Posted 02 March 2016 - 01:12 PM

for ( int w = 0; q < 176; w++ ){

That looks like the problem. Should be w instead of q.


  • AdmiralJaden likes this

#18 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 02 March 2016 - 03:01 PM

for ( int w = 0; q < 176; w++ ){

That looks like the problem. Should be w instead of q.

 

That did solve the freezing problem, thank you.
-although-

The script seems to have no effect (that I can see), the screen only lights up when the candle's flame is on screen, then darkens again (like it should, if the candle were all that's being used), even with my lit torch combo on screen.
In other words, lit torch doesn't keep the room lit.

I don't know if it's the script, or something I'm doing, or if it's not working with the aforementioned rule for some reason.
But, I'm sure you all will figure it out, it's just odd lol.



#19 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 03 March 2016 - 12:54 AM

That did solve the freezing problem, thank you.
-although-

The script seems to have no effect (that I can see), the screen only lights up when the candle's flame is on screen, then darkens again (like it should, if the candle were all that's being used), even with my lit torch combo on screen.
In other words, lit torch doesn't keep the room lit.

I don't know if it's the script, or something I'm doing, or if it's not working with the aforementioned rule for some reason.
But, I'm sure you all will figure it out, it's just odd lol.

 

(1)  When you compiled, did you assign the global script 'active' to 'slot 2/active' int he global scripts assignment tab?

(2) Did you start a fresh save slot?

 

Both of these are mandatory.


Edited by ZoriaRPG, 03 March 2016 - 12:54 AM.


#20 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 03 March 2016 - 07:41 AM

(1)  When you compiled, did you assign the global script 'active' to 'slot 2/active' int he global scripts assignment tab?

(2) Did you start a fresh save slot?

 

Both of these are mandatory.

1. Yes

2. No, that might be the problem, let me check.

 

Edit: Checked with a new save slot as well, same result.


Edited by AdmiralJaden, 03 March 2016 - 07:44 AM.


#21 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 04 March 2016 - 01:43 AM

1. Yes

2. No, that might be the problem, let me check.

 

Edit: Checked with a new save slot as well, same result.

 

I see why... When I wrote this, I originally intended it to parse layer 0, then I decided to parse all layers for the desired combo. That's why that earlier for loop error existed, and incidentally, i forgot to change the variable used to check the screen combo index.

 

Try this:

//import "std.zh"
    //Remove the comment before the import directive
    //instruction if you do not elsewhere call this.

/////////////////////////////////////////
// Basic : Lit Torches Dispel Darkness //
//     v0.3 - 3rd March, 2016          //
//         By: ZoriaRPG                //
///////////////////////////////////////////////////////////////////////////////////
// This script set creates a fading darkness effect when a lit torch set by the  //
// constant 'CMB_LIT_TORCH'.                                                     //
// ----------------------------------------------------------------------------- //
// [ 1 ] Set-Up: Make a 'lit torch' combo, and assign its ID to the constant     //
//       CMB_LIT_TORCH.                                                          //
// [ 2 ] Set up a combo on the screen with a secret flag (burn).                  //
//       Set the 'burn' combo in Screen->Secret Combos to match the combo that   //
//       you selected as 'CMB_LIT_TORCH'.                                        //
///////////////////////////////////////////////////////////////////////////////////

//////////////
// SETTINGS //
//////////////

//Combo and Colour Constants

const int CMB_LIT_TORCH             = 0;    //Set to the combo number of the torch in its lit state.
const int TORCH_HIGHEST_LAYER       = 6; //The highest layer on which a lit torch combo can appear.

/////////////////////
// ARRAYS AND VARS //
/////////////////////

float GRAM[214727]; //Global Array to hold values.

//Array indices:
const int GR_MAIN       = 214747;
const int GR_MAIN_SET   = 214746;

const int SIMPLE_TORCH_DEBUG_ENABLED    = 1;
const int MAIN_DEBUG_ENABLED            = 1;

/////////////////////////////////////
// DARKNESS AND LIGHTING FUNCTIONS //
/////////////////////////////////////

//The primarycomponent function, called by Torches()
void SimpleLightRoom(){
    if ( !Screen->Lit ) {
        for ( int q = 0; q <= TORCH_HIGHEST_LAYER; q++ ) { //layers
            if (Screen->LayerMap(q) != -1) {
                for ( int w = 0; w < 176; w++ ){
                    if ( Screen->ComboD[w] == CMB_LIT_TORCH ) {
                        if ( SIMPLE_TORCH_DEBUG_ENABLED ){
                            int foundtorch[]="Screen was dark. Found a lit torch on layer: ";
                            int founttorchpos[]="At combo position: ";
                            int litscreen[]="and lit Screen: ";
                            int litscrdmap[]="on DMap: ";
                            TraceNL(); TraceS(foundtorch); Trace(q); TraceS(founttorchpos); Trace(w);
                            TraceNL(); TraceS(litscreen); Trace(Game->GetCurScreen()); TraceS(litscrdmap); Trace(Game->GetCurDMap());
                        }
                        Screen->Lit = true;
                    }
                }
            }
        }
    }
}

///////////////////
// GLOBAL SCRIPT //
///////////////////

global script active_example_timed_fading_torch_darkness{
    void run() {
        main(true); //Enable the main loop.
        if ( !GRAM(GR_MAIN_SET) ) {
            Trace(main());
            GRAM(GR_MAIN_SET,1);   
        }            
        while( main() ) {       //! I do this, instead of while(true) to allow suspending it,
                                //! and changing to an alternate global loop, as an option.
            
            SimpleLightRoom(); //The main function for custom darkness (no special effects version)
     
            Waitdraw();

            Waitframe();
        }
    }
    int main() { return GRAM(GR_MAIN); }

    void main(bool enabled) {
        if ( enabled ) GRAM(GR_MAIN,1);
        else GRAM(GR_MAIN,0);
    }
}

int GRAM(int index){ return GRAM[index];} //Returns the value of specified index of Global RAM array.
void GRAM(int index, int val){GRAM[index]=val;} //Sets Global RAM array index to a specific value.

I added some traces in there so that if it doesn't work, I might discover why. If it does work, replace it with this:

 

Spoiler

Edited by ZoriaRPG, 04 March 2016 - 01:50 AM.


#22 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 04 March 2016 - 09:11 AM

That first one works perfectly! Thank you again for taking the time to make this for me. :)

I'll be sure to mention you (all) in my project as well.



#23 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 05 March 2016 - 11:24 AM

That first one works perfectly! Thank you again for taking the time to make this for me. :)

I'll be sure to mention you (all) in my project as well.

 

As I said, if the first one works, replace it with the second one. All those Traces are good for debugging, but they will s, so use the second one in the last post, that doesn't have them. I'll work on the version that fades in and out, when I have the time. Once done, you will be able to drop it in as a direct replacement.

 

I feel sort of feel awful that I had to post so many revisions to make this, as it's absurdly simple. The problem is two-file: (1) I'm writing it on an 8-inch screen, with a micro-keyboard, that's a huge pain to either type on or see; and (2) this system is severely limited in terms of power, and runs very slow with only the browser, my coding IDE, Scintilla, Skype, and NVC running.

 

ZC eats up so much CPU time, RAM, and such, that if I tried to run concurrent instances of it, and do testing, things would start crashing. As I've been in the heart of a big machining and fabrication (mechanical engineering) project, I really only have short breaks during which I may write this code; and because I don;t have room for my larger systems, I only carry the netbook.

 

Once I have at least a week (two, or three would be better), I can sit down and finish some of these projects, and do live testing. I don't even have my ZScript syntax highlighting, or other SciTE prefs on here, so it's just plain text in black and white, which in the tiny screen, is even harder to see.

 

I don't usually post code that has errors like these, and it's sort of a black spot for me, but trying to be helpful on the forums while pushing 90-hours a week in fab work, is to say the least, tedious.

 

Luckily, the biggest project is around 85% to 85% complete, the medium project around 30%, and the other is low priority. I will have others coming up, but I should have at least a one-week period in late march that might afford me the time that I need to catch up. I essentially have half-an-hour a day to devote to ZC support at present, so I've been hammering these out very fast, and not closely examining them for errors.

 

A few of those though, cropped up because the scripts are designed to use one of my general headers. I posted the constants, and functions in the complex one, but I neglected to copy them into the simple one, and I also missed a few variable calls and returns when I modified things due to rushing it up.

 

I think I'll post the simple torch script tot he database though.

 

Do me a favour, and tell me if this works:

//import "std.zh"
    //Remove the comment before the import directive
    //instruction if you do not elsewhere call this.

/////////////////////////////////////////
// Basic : Lit Torches Dispel Darkness //
//     v0.4 - 5th March, 2016          //
//         By: ZoriaRPG                //
///////////////////////////////////////////////////////////////////////////////////
// This script set creates a fading darkness effect when a lit torch set by the  //
// constant 'CMB_LIT_TORCH'.                                                     //
// ----------------------------------------------------------------------------- //
// [ 1 ] Set-Up: Make a 'lit torch' combo, and assign its ID to the constant     //
//       CMB_LIT_TORCH.                                                          //
// [ 2 ] Set up a combo on the screen with a secret flag (burn).                  //
//       Set the 'burn' combo in Screen->Secret Combos to match the combo that   //
//       you selected as 'CMB_LIT_TORCH'.                                        //
///////////////////////////////////////////////////////////////////////////////////

//////////////
// SETTINGS //
//////////////

//Combo and Colour Constants

const int CMB_LIT_TORCH             = 0;    //Set to the combo number of the torch in its lit state.
const int TORCH_HIGHEST_LAYER       = 6;    //The highest layer on which a lit torch can appear.

/////////////////////
// ARRAYS AND VARS //
/////////////////////

float GRAM[214727]; //Global Array to hold values.

//Array indices:
const int GR_MAIN       = 214747;

/////////////////////////////////////
// DARKNESS AND LIGHTING FUNCTIONS //
/////////////////////////////////////

//The primarycomponent function, called by Torches()
void SimpleLightRoom(){
    float torchCombos[]={CMB_LIT_TORCH};
    if ( !Screen->Lit ) {
        for ( int q = 0; q <= TORCH_HIGHEST_LAYER; q++ ) { //layers
            if (Screen->LayerMap(q) != -1) {
                for ( int w = 0; w < 176; w++ ){
                    if ( __MatchComboD(torchCombos, w) ) {
                        Screen->Lit = true;
                    }
                }
            }
        }
    }
}

//Compares combo 'cmb' and compares it to the values in array 'list'.
//Returns true of any of the entries on the list match its Data.
bool __MatchComboD(int list, int cmb){
    bool match = false;
    for ( int q = 0; q < SizeOfArray(list); q++ ) {
        if ( Screen->ComboD[cmb] == list[q] ) match = true;
    }
    return match;
}

///////////////////
// GLOBAL SCRIPT //
///////////////////

global script active_example_timed_fading_torch_darkness{
    void run() {
        main(true); //Enable the main loop.
        while( main() ) {       //! I do this, instead of while(true) to allow suspending it,
                                //! and changing to an alternate global loop, as an option.
            
            SimpleLightRoom(); //The main function for custom darkness (no special effects version)
     
            Waitdraw();

            Waitframe();
        }
    }
    int main() { return GRAM(GR_MAIN); }

    void main(bool enabled) {
        if ( enabled ) GRAM(GR_MAIN,1);
        else GRAM(GR_MAIN,0);
    }
}

void GRAM(int index, int val){GRAM[index]=val;} //Sets Global RAM array index to a specific value.
int GRAM(int index){ return GRAM[index];} //Returns the value of specified index of Global RAM array.

If so, please use that one, as it is what I will be uploading to the database.

 

It's a slight improvement, as it supports using more then one combo as a 'lit torch', simply by expanding a list..


Edited by ZoriaRPG, 05 March 2016 - 11:54 AM.

  • AdmiralJaden likes this

#24 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 05 March 2016 - 12:36 PM

Works perfectly. :)



#25 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 05 March 2016 - 02:36 PM

Works perfectly. :)

 
Good, good. If you ever need to add more torch combos, the list is here:
 
 

void SimpleLightRoom(){
    float torchCombos[]={CMB_LIT_TORCH};

 
Just add more combos to the list, either hardcoded:
 

 
void SimpleLightRoom(){
    float torchCombos[]={CMB_LIT_TORCH,87,2134};
    //Adds combos 87 and 2134 as lit torches

 
or...set constants for them, and add them by constant:
 
 

 
const int CMB_LIT_TORCH_BLUE = 87;
const int CMB_LIT_TORCH_GREEN = 2134;
 
void SimpleLightRoom(){
    float torchCombos[]={CMB_LIT_TORCH, CMB_LIT_TORCH_BLUE,CMB_LIT_TORCH_GREEN};

 
That allows you to have more than one type, by style, design, colour, or whatever.
 
Also, figure out what the highest layer you will use for lit torches will be, and change this constant to match the layer:
 

const int TORCH_HIGHEST_LAYER       = 6;    //The highest layer on which a lit torch can appear.

 
Thus, if torches will only be on layer 0, change the '6' to a '0'. If they will be on layers 0 and 1, change it to a '1', if on layers 0,1, and 2, change it to a '2'.and so on. That will increase performance by shortening the loop iterations, and is why I changed it to a constant.

These changes require recompiling, but they do not need a new save file.
 
The script is smart enough not to check layers is they aren't set up though, so you can make some screens with only layer 0, or 0 and 1, and some with 0, 1, 2, 3 and 4, and set that value to the highest layer on which you will ever have a lit torch, and if it is on a screen without those layers, then they won't be checked..
 
I could have added break statements for even more optimisation, but I'll save that for the version that I add to the database.

I'm not too concerned with being credited. I just ask that you finish the quest, and don't abandon it. :D

I hate to see things go to waste.


Edited by ZoriaRPG, 05 March 2016 - 02:41 PM.


#26 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 05 March 2016 - 03:34 PM

Nice! And will do, I'm having a lot of fun with zquest so far too. It brings back some good memories, working with it.



#27 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 06 March 2016 - 10:20 PM

Ok, a question. Ran into an unexpected snag.

I'm wanting to use a custom boss (Armos Knights from alttp), but that uses the "GhostZHActiveScript" global script, which, of course, erases this one.

My question is, how would I incorporate this script into that global, or that global into this one, so I could use both?



#28 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 07 March 2016 - 03:12 AM

Ok, a question. Ran into an unexpected snag.

I'm wanting to use a custom boss (Armos Knights from alttp), but that uses the "GhostZHActiveScript" global script, which, of course, erases this one.

My question is, how would I incorporate this script into that global, or that global into this one, so I could use both?

 

You add the functions to the existing global active script, whichever way you prefer. It'll look like this:

 

//import "std.zh"
//import "ffcscript.zh"
//import "ghost.zh"
    //Remove the comment marks ('//') before the import directive
    //instructions if you do not elsewhere call these.

/////////////////////////////////////////
// Basic : Lit Torches Dispel Darkness //
//      v0.4 - 5th March, 2016         //
//          By: ZoriaRPG               //
///////////////////////////////////////////////////////////////////////////////////
// This script set creates a fading darkness effect when a lit torch set by the  //
// constant 'CMB_LIT_TORCH'.                                                     //
// ----------------------------------------------------------------------------- //
// [ 1 ] Set-Up: Make a 'lit torch' combo, and assign its ID to the constant     //
//       CMB_LIT_TORCH.                                                          //
// [ 2 ] Set up a combo on the screen with a secret flag (burn).                 //
//       Set the 'burn' combo in Screen->Secret Combos to match the combo that   //
//       you selected as 'CMB_LIT_TORCH'.                                        //
// [ 3 ] If you wush to use more than one combo as a lit torch, populate the     //
//       array 'torchCombos[]', in the function SimpleLightRoom() at line '48'   //
//       with the combo numbers or with self-defined constantsd that you assign  //
//       to those values, separated by commas.                                   //
///////////////////////////////////////////////////////////////////////////////////

//////////////
// SETTINGS //
//////////////

//Combo and Colour Constants

const int CMB_LIT_TORCH             = 0;    //Set to the combo number of the torch in its lit state.
const int TORCH_HIGHEST_LAYER       = 6;    //The highest layer on which a lit torch can appear.

/////////////////////
// ARRAYS AND VARS //
/////////////////////

float GRAM[214727]; //Global Array to hold values.

//Array indices:
const int GR_MAIN       = 214747;

/////////////////////////////////////
// DARKNESS AND LIGHTING FUNCTIONS //
/////////////////////////////////////

//The primarycomponent function, called by Torches()
void SimpleLightRoom(){
    float torchCombos[]={CMB_LIT_TORCH}; //Populate with combos that you want to use as lit torches, separated by commas.
    if ( !Screen->Lit ) {
        for ( int q = 0; q <= TORCH_HIGHEST_LAYER; q++ ) { //layers
            if (Screen->LayerMap(q) != -1) {
                for ( int w = 0; w < 176; w++ ){
                    if ( __MatchComboD(torchCombos, w) ) {
                        Screen->Lit = true;
                    }
                }
            }
        }
    }
}

//Compares combo 'cmb' and compares it to the values in array 'list'.
//Returns true of any of the entries on the list match its Data.
bool __MatchComboD(int list, int cmb){
    bool match = false;
    for ( int q = 0; q < SizeOfArray(list); q++ ) {
        if ( Screen->ComboD[cmb] == list[q] ) match = true;
    }
    return match;
}

///////////////////
// GLOBAL SCRIPT //
///////////////////

global script active_example_timed_fading_torch_darkness{
    void run() {
        main(true); //Enable the main loop.
        StartGhostZH();
        while( main() ) {       //! I do this, instead of while(true) to allow suspending it,
                                //! and changing to an alternate global loop, as an option.
            
            SimpleLightRoom(); //The main function for custom darkness (no special effects version)
            UpdateGhostZH1();
            Waitdraw();
            
            UpdateGhostZH2();
            Waitframe();
        }
    }
    int main() { return GRAM(GR_MAIN); }

    void main(bool enabled) {
        if ( enabled ) GRAM(GR_MAIN,1);
        else GRAM(GR_MAIN,0);
    }
}

void GRAM(int index, int val){GRAM[index]=val;} //Sets Global RAM array index to a specific value.
int GRAM(int index){ return GRAM[index];} //Returns the value of specified index of Global RAM array.
 

 

You may only have one of each of the four types of global scripts running at any given time. If you wish to have more than one type of loop, that is my purpose of calling while ( main() ) as this allows advanced loop control, rather than a standard while(true) infinite loop, as it is possible to suspend the main() condition. If that sounds like gibberish, don't fret, you'll eventually get it. :D



#29 AdmiralJaden

AdmiralJaden

    Experienced Forumer

  • Members

Posted 07 March 2016 - 10:49 AM

Lol I think I understand the idea: It's supposed to check to see which case is true at that moment, and run that section rather than trying to run every global in the script continuously like it usually does.

Tested: Tested it, the ghost script (and by extension, the boss) works fine now, but the rooms with the torches won't stay lit.



#30 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 07 March 2016 - 07:42 PM

Lol I think I understand the idea: It's supposed to check to see which case is true at that moment, and run that section rather than trying to run every global in the script continuously like it usually does.

Tested: Tested it, the ghost script (and by extension, the boss) works fine now, but the rooms with the torches won't stay lit.

 

Either you didn't assign the correct global script, or, that you didn't make a new save file. Ghost.zh uses arrays, and the array pointers are assigned numerically in reverse order, so the pointer for GRAM[] would be superseded by the ghost[] array. Actually, if main() is being set, then

 

I'm betting on incorrect script assignment.

 

Check that you assigned the script 'active_example_timed_fading_torch_darkness', from the above post, to slot 2 (active), and not 'GhostZHActiveScript'. If you did, then ensure that you have a new save slot.

 

If that all checks out, and it still does not work, then it may be a problem with priorities, although I'ven't any idea why.

 

Flipping these function calls:

 

            SimpleLightRoom(); //The main function for custom darkness (no special effects version)
            UpdateGhostZH1();

 

...to this...

 

            UpdateGhostZH1();
            SimpleLightRoom(); //The main function for custom darkness (no special effects version)

 

...might do it, if all else fails, but I don't know any reason that ghost.zh would interrupt screen states.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users