Script: Several Questions

Started by Kikutaâ„¢, Mon 07/03/2005 15:35:07

Previous topic - Next topic

Kikutaâ„¢

Hi :)

Ok, i got several questions.

1st-> I made a lightbulb blink in a cenario. I made it as an object, instead of using the background animating. The lightbulb blinks randomly and it has sound. It's all ok, except on thing. I've made a region below the light, so as it blinks, the character gets the light. But since it's random, it's a bit difficult. I've code this :
Code: ags

if (GetObjectGraphic(0)==152) SetAreaLightLevel(1,110);

Teoricly, it works, but it doesnt work. I dont know if the problem is from the function AnimateObject.



2nd-> I've made a costume inventory screen. Everythings works fine, except one little thing. If the inventory item image is too big, when i click in the bottom part and lright part of it, it reacts as if it's clicking on nothing. I think that if the image is bigger than 50*50 when you click out side the 50*50 area , the on_click_event doesnt run (i think!)

Is there anyway i can change it ?

3rd-> If i copy the example of StrCopy to the beggining of the main global script file, it gives " parce error". I dont know why. The code is :
Code: ags

string message;
StrCopy(message,"This is a message"); 

Anyone knows why does this happen ?


That's all! Thank you for reading this, and sorry about my english :P



Ashen

#1
1.
Where in the script have you put that code? Also, is the character definately standing on the area affected? And not set to 'ignore room area lighting' (a checkbox on the Character window)?

2.
Have a look at SetInvDimentions (height, width), that might be able to help.

3.
Again, where exactly in the script is it? If it's just at the top of the global script, outside all functions, it would've said "Parse error: unexpected 'StrCopy'". If so, you need to move the second line into a function - which one depends on why you want it there in the first place.
I know what you're thinking ... Don't think that.

Kikutaâ„¢

1. i've put this in the room's repeatedly execute.
Code: ags

// script for room: Repeatedly execute
a=Random(30);
AnimateObject(0,1,a,1);


I've made that , if the player stand in the region, it would do
Code: ags

if (GetObjectGraphic(0)==152) SetAreaLightLevel(1,110);

The object has only two frames. The first one is 0, and the secound is 152.
And yes, my character is affected by the area lighting.

2. Thanks!!! I've searched everywhere! How could i miss that? Thank you very much.

3. Yeah, i've made it before the functions. But, I have many values beeing assined in the top of global script. Wierd thing. I'll try that, thanks.

Ashen

1.
Try shifting the if (GetObjectGraphic(0)==152) ... line into the rep-ex as well.
Also, as it is, it's possible that the object's graphic is never 152 (the animation is restarted so often, it never reaches the second frame), so it would never have an effect. Try replacing the whole thing with:
Code: ags

// script for room: Repeatedly execute
a=Random(30);
if (a == 30) SetObjectGraphic (0, 152);
else SetObjectGraphic (0, 0);
if (GetObjectGraphic(0)==152) SetAreaLightLevel(1,110);

(I'm assuming the int a has been declared somewhere else.)

3.
But are the other values strings or ints? To set a string at the start of the game, declare it at the very top (the string message; line), but it's probably best to set it (StrCopy (message,"This is a message"); or StrFormat (message,"This is a message");) in the game_start function.
I know what you're thinking ... Don't think that.

RickJ

1.  You calculate the annimation delay coirrectly bu you don't give the engine to carry out the AnimateObject() instruction.  The delay means how many executions of the game engine to leave between frames of the animation.   So you keep recalculating this delay every execution of the engine so it doesn't work.  Try this instead:
   // script for room: Repeatedly execute
   if (IsObjectAnimating (0)==0) { 
      a=Random(30);
      AnimateObject(0,1,a,0);
   }


The second problem I see is that I am not sure that GetObjectGraphic() returns the the graphic of the current frame in an animation.  I may be wrong, but it's my guess is that it returns the graphic assigned in the AGS editor.   So my solution would be to do the whole thing like this:
// Room Script
#define LIGHTBULB_VIEW 10
#define LIGHTBULB_LOOP  0
#define LIGHTBULB_FRAMES 5
#define LIGHTBULB_MAX  100
#define LIGHTBULB_MIN -100

int LightBulbFrame=0;
int LightBulbDelay=0;
int LightBulbTime=0;

function LightBulbAnimation() {
   int light_level;

   if (LightBulbTime<=0) {
      LightBulbTime = LightBulbDelay;
      LightBulbFrame++;
      if (LightBulbFrame>LIGHTBULB_FRAMES) {
         LightBulbFrame = 0;
      }
      else {
         LightBulbDelay = Random(30)+1;
         SetObjectFrame (0, LIGHTBULB_VIEW, LIGHTBULB_LOOP, LightBulbFrame);
         light_level = (((LIGHTBULB_MAX-LIGHTBULB_MIN)*LightBulbFrame)/LIGHTBULB_FRAMES)+LIGHTBULB_MIN;
         SetAreaLightLevel(1,light_level);
      }
   }
   else {
      LightBulbTime--;
   }
}

// Repeatedly Execute
function room_a() {
   LightBulbAnimation()
}


3.  You can declare variables outside the bounds of functions.  Such variables retain their value for the session.   Variables declared within the bounds of a function only retain their values during the execution of the function.  The next time the function is called the values of such variables are not retained.  Executable statements can't be putside the bounds of a function because they will never be executed. 


Kikutaâ„¢

Thanks Ashen and thank you RickJ. I shall try what you have said ;D

SMF spam blocked by CleanTalk