"if" problem (now with script)

Started by saanb, Mon 30/06/2003 12:48:22

Previous topic - Next topic

saanb

for different hotspots i have scripts for interacting with them. i put if something do this. if something do that. i actually don't think that's the problem though because no matter which hotspot i click on, it does the same thing, something which i only wrote under one hotspot for interacting with it. any idea what's wrong?
here's the script:

function hotspot1_d() {
 // script for hotspot1: Use inventory on hotspot
RawDrawImage(65, 40, 21);  
Wait(160);
RawDrawImage(65, 40, 22);
RawSaveScreen();
screen = 1;
}

function hotspot2_a() {
 // script for hotspot2: Interact hotspot
if (screen == 1) {RawDrawImage(65, 40, 23);  
Wait(120); RawRestoreScreen(); screen = 1;}
if (screen == 2) {RawDrawImage(65, 40, 25); screen = 3;}
if (screen == 3) {RawDrawImage(65, 40, 26); SetGlobalInt(2,4); NewRoom(4);}
}

function hotspot3_a() {
 // script for hotspot3: Interact hotspot
if (screen == 1) {RawDrawImage(65, 40, 24); screen = 2;}
if (screen == 2) {RawDrawImage(65, 40, 23);
Wait(120); RawRestoreScreen(); screen = 1;}
if (screen == 3) {RawDrawImage(65, 40, 23);
Wait(120); RawRestoreScreen(); screen = 1;}
}

if you're wondering what this is supposed to do, it's for a panel with buttons and a screen. everytime i click on either of the hotspots(buttons), it draws image 23 and restores the screen.

Scorpiorus

Remember that changing screen variable leads to running the code of the next if provided the var's new value sets it's condition to be true. So you need something like that instead:

function hotspot1_d() {
// script for hotspot1: Use inventory on hotspot
RawDrawImage(65, 40, 21);
Wait(160);
RawDrawImage(65, 40, 22);
RawSaveScreen();
screen = 1;
}

function hotspot2_a() {
// script for hotspot2: Interact hotspot
if (screen == 1) {RawDrawImage(65, 40, 23);
Wait(120); RawRestoreScreen(); screen = 1;}
else if (screen == 2) {RawDrawImage(65, 40, 25); screen = 3;}
else if (screen == 3) {RawDrawImage(65, 40, 26); SetGlobalInt(2,4); NewRoom(4);}
}

function hotspot3_a() {
// script for hotspot3: Interact hotspot
if (screen == 1) {RawDrawImage(65, 40, 24); screen = 2;}
else if (screen == 2) {RawDrawImage(65, 40, 23);
Wait(120); RawRestoreScreen(); screen = 1;}
else if (screen == 3) {RawDrawImage(65, 40, 23);
Wait(120); RawRestoreScreen(); screen = 1;}
}

which will ensure that only one if is run per script execution.

-Cheers

SMF spam blocked by CleanTalk