Problem With Custom Variables [SOLVED]

Started by Mikhail, Sun 18/03/2012 20:09:35

Previous topic - Next topic

Mikhail

I've create an own variable (my_click) with default value..

but i've problem when use it on room script because it'll conflict with same custom variable i use it on different hotspot in the same room..the func look continued culculating in other hotspot without reset to normal clicking count.

Code: ags

function PlateLucas_Look()
{
  my_click++;
  
  if (my_click <= 1) {
  
  DisableInterface();
  
   cLucas.Say("It spells my name..");
    Wait(40);
   cLucas.Say("???");
   
   EnableInterface();
  }
  
  else {
    
    Display("It spells my name.. LUCAS");
  }
}



function hCage_OW_Interact()
{
 my_click++;
 
 if (my_click <= 2) {
 
 Display("I don't want to touch it.");
}

 else if (my_click < 6) {
   
 Display("No way.. man ..");
 }
 
 else {
   Display("You SUCK man..");
 }
}


PlateLucas is an object while hCage_OW is the hotspot..

Anytime when i clicking the Cage (hotspot) and change to clicking to PlateLucas (object),the

Code: ags
 
my_click++;
  
  if (my_click <= 1) {
  
  DisableInterface();
  
   cLucas.Say("It spells my name..");
    Wait(40);
   cLucas.Say("???");
   
  EnableInterface();
  }


not trigger and reset or change itself to else statement below;

Code: ags

Display("It spells my name.. LUCAS");


how can i reset the variable to original or default state before i clicking the PlateLucas (object) after clicking Cage (hotspot)

well..the other problem is when i clicking the PlateLucas (object) first, then change clicking to Cage (hotspot), the variable trigger and change itself to else if then following to else statement below;

Code: ags

...

else if (my_click < 6) {
  Display("No way.. man ..");
 }
 
 else {
   Display("You SUCK man..");
 }
}


well..how can i reset the both of this variable to original or default state?

Khris

#1
First of all, what's with the Disable/EnableInterface() calls in the first function?
cLucas.Say() and Wait() are blocking commands, so the interface should be disabled anyway.

Now, to answer your question, resetting the variable to its default value would make its existence purposeless. The whole point of the variable is storing how many times the object was clicked.

Now, as you found out, since you're using the same variable for both the object and hotspot, they keep interfering with each other. You obviously need a second variable to store the clicks on both hotspots independently. And a new variable for each new hotspot, too.

The good thing though is that you're probably not going to need most of them outside the room, so you don't have to set up tons of Global variables. Just put them at the top of the room script or above the first function that uses them:

Code: ags
int platelucas_clicks;  // no value stated means initialized as 0 for ints

function PlateLucas_Look()
{
  platelucas_clicks++;
  
  if (platelucas_clicks <= 1) {
    cLucas.Say("It spells my name..");
    Wait(40);
    cLucas.Say("???");
  }
  else {
    Display("It spells my name.. LUCAS");
  }
}

Mikhail

Finally it's work nicely..thankss khris..  ;D

SMF spam blocked by CleanTalk