Hi all.
I have again problem with a very difficult code.
(https://gamesolutions.efzeven.nl/images/leisuresuitlarry2pnc-walkthrough.png)
As you can see from this image from Leisure Suit Larry 2. The Luggage slides from left to right.
When it on the region where the x-ray window it shows a x-ray image sprite. When it slides out it shows the luggage and it continues to slide right.
And then it begins from the start, sliding another x-ray sprite image on the slider and another luggage image appears too when it comes out of from the x-ray window.
I hope you understood me.
I have two region for this. Region 2 and Region 4.
When the object is on region 2 I want to change the image of the graphic.
And again when it slides on region 4.
In First Loading screen my code is:
SetTimer(1,275);
Here is my code.
i function room_RepExec()
{
oThings.X= -50; oThings.Y=158;
if (!oThings.Moving){
oThings.Move(310, 157, -3, eNoBlock, eAnywhere);
}
/////This code lets the object slide from right to left endless.
Region* Taska1 = Region.GetAtScreenXY(oThings.X, oThings.Y);
if (Taska1 == region[4]) {
oThings.Graphic=5903;
SetTimer(1, 175);
}
if (Taska1 != region[4]) {
if (IsTimerExpired(1)){
oThings.Graphic=1425;
SetTimer(2, 800);
}
}
}
This code works! The graphic changed in each times the object slides on Region 4 and when it is off the Region 4.
And it continues to move from left to right. And it returns back on the same spot where the object start to move from left to right.
But the problem is I want to change the graphic again 12 times when it goes on same region 4
I hope you can help me with this because this is so difficult for me.
I also tried this code.
function room_RepExec()
{
oThings.X= -50; oThings.Y=158;
if (!oThings.Moving){
oThings.Move(310, 157, -3, eNoBlock, eAnywhere);
}
if (IsTimerExpired(2)){
SetTimer(1, 0);
oThings.Graphic= 1429;
SetTimer(3, 275);
}
else if (IsTimerExpired(3)){
SetTimer(2, 0);
oThings.Graphic= 5894;
SetTimer(4, 800);
That code worked great until I found out about this in Help section: There are 20 available timers, with TIMER_IDs from 1 to
So I could add more Settimer. I hope that will be changed in the next update.
edit......
Thanks to Crimson Wizard he solved this for me. Case Closed.
// Set these according to your game
#define POSITION_START_MOVE 0
#define POSITION_CHANGE_GRAPHIC 100
#define POSITION_END_MOVE 310
function room_RepExec()
{
// If thing is not moving OR if it just went all the way to the right -
if (!oThing.Moving || oThing.X >= POSITION_END_MOVE) {
// Move thing back
oThing.X = POSITION_START_MOVE;
// Switch to next object's x-ray graphic (set to your sprites accordingly)
switch (oThing.Graphic) {
case 1001: oThing.Graphic = 1100; break;
case 1101: oThing.Graphic = 1200; break;
case 1201: oThing.Graphic = 1300; break;
//... etc
}
// Begin moving through x-ray window
oThings.Move(POSITION_END_MOVE, 157, -3, eNoBlock, eAnywhere);
}
// If thing was moving and just passed x-ray window
else if (oThing.Moving && oThing.X > POSITION_END_MOVE) {
// Change from x-ray to normal graphic (set to your sprites accordingly)
switch (oThing.Graphic) {
case 1000: oThing.Graphic = 1001; break;
case 1100: oThing.Graphic = 1101; break;
case 1200: oThing.Graphic = 1201; break;
//... etc
}
}
}
Why not just do something like this?:
function room_RepExec()
{
if ((Region.GetAtRoomXY(oThings.x, oThings.y) == region[4]) && (oThings.Graphic!=5903)) oThings.Graphic=5903;
else if ((Region.GetAtRoomXY(oThings.x, oThings.y) != region[4]) && (oThings.Graphic!=1425)) oThings.Graphic=1425;
}
That code works fine too.
But how am I suppose to change the graphic on the same object again 12 times when it is sliding on the same region?
The luggage are 6 and it must go in x-ray first and come out as a normal luggage on the slider.
The region 4 is where the graphic change into luggage.
And on the Region 2 is where the X-Ray images of the luggage goes through.
Fribbi, judging by what you do, you don't need more timers, you can use 1 timer and increment some integer variable to know how many times event repeated.
Speaking of timers in general, they are very primitive in AGS and you can easily script similar yourself in any quantities. All AGS timers do is decrement tick counts each update, which may be equivalent of doing same in "rep-exec" function until it reaches zero.
How?
I still need help with this. Coding this are really giving me headache.
This sounds like it could be solved easily, but I don't really get it yet. What do you mean by this:
Quote from: Fribbi on Sun 28/03/2021 00:06:59
But how am I suppose to change the graphic on the same object again 12 times when it is sliding on the same region?
The luggage are 6 and it must go in x-ray first and come out as a normal luggage on the slider.
My guess is that there are supposed to be six luggage bags moving from left to right, one after the other? Do they look differently? Are the x-ray images supposed to look differently?
Instead of using timers and regions you could simply check the x coordinate of the object and change it's graphic accordingly. Arjon's code should also work regardless of how many times the object is supposed to change it's graphic.
If you have played Leisure suit Larry 2. You should see what I meant. But in one scenery there are luggage coming out one after one another.
And it goes from left to right.
Something like this,
// Set these according to your game
#define POSITION_START_MOVE 0
#define POSITION_CHANGE_GRAPHIC 100
#define POSITION_END_MOVE 310
function room_RepExec()
{
// If thing is not moving OR if it just went all the way to the right -
if (!oThing.Moving || oThing.X >= POSITION_END_MOVE) {
// Move thing back
oThing.X = POSITION_START_MOVE;
// Switch to next object's x-ray graphic (set to your sprites accordingly)
switch (oThing.Graphic) {
case 1001: oThing.Graphic = 1100; break;
case 1101: oThing.Graphic = 1200; break;
case 1201: oThing.Graphic = 1300; break;
//... etc
}
// Begin moving through x-ray window
oThings.Move(POSITION_END_MOVE, 157, -3, eNoBlock, eAnywhere);
}
// If thing was moving and just passed x-ray window
else if (oThing.Moving && oThing.X > POSITION_END_MOVE) {
// Change from x-ray to normal graphic (set to your sprites accordingly)
switch (oThing.Graphic) {
case 1000: oThing.Graphic = 1001; break;
case 1100: oThing.Graphic = 1101; break;
case 1200: oThing.Graphic = 1201; break;
//... etc
}
}
}
Thank you Crimson Wizard, it worked! ;-D Finally can I go forward on this work. I have never see a code like this before but it worked.
But I made a little adjustment on this code. It now works perfectly.
Thanks again all!
Case closed! And feel free if anyone here want that free code that is if you want that code for your own game creations.
// room script file
int Secret = 0;
#define POSITION_START_MOVE 0
#define POSITION_CHANGE_GRAPHIC 110
#define POSITION_END_MOVE 310
function room_RepExec()
{
// If thing is not moving OR if it just went all the way to the right -
if (!oThings.Moving || oThings.X >= POSITION_END_MOVE) {
// Move thing back
oThings.X = POSITION_START_MOVE;
// Switch to next object's x-ray graphic (set to your sprites accordingly)
switch (oThings.Graphic) {
case 1425: oThings.Graphic = 1425; break;
case 5903: oThings.Graphic = 1427; break;
case 5892: oThings.Graphic = 1428; break;
case 5893: oThings.Graphic = 1429; break;
case 5894: oThings.Graphic = 1430; break;
case 5895: oThings.Graphic = 1431; break;
//... etc
}
// Begin moving through x-ray window
oThings.Move(POSITION_END_MOVE, 157, -3, eNoBlock, eAnywhere);
}
// If thing was moving and just passed x-ray window
else if (oThings.Moving && oThings.X > POSITION_CHANGE_GRAPHIC) {
// Change from x-ray to normal graphic (set to your sprites accordingly)
switch (oThings.Graphic) {
case 1425: oThings.Graphic = 5903; break;
case 1427: oThings.Graphic = 5892; break;
case 1428: oThings.Graphic = 5893; break;
case 1429: oThings.Graphic = 5894; break;
case 1430: oThings.Graphic = 5895; break;
//... etc