Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: vjamesv on Fri 19/01/2007 04:26:15

Title: SpinLock Module: basic help
Post by: vjamesv on Fri 19/01/2007 04:26:15
I am trying to get the SpinLock module working in my game, and so far I have gotten the left and right buttons working correctly where they spin the dial, but i am not sure how to test if the correct combination has been tested.  i used the code included in the readme file which is:


if (SpinLock.SpinRight()){
  Display("You figured it out!");
}

and i put that code in the interaction for the right arrow button.  after i did that when i used the button it would turn the dial by two numbers instead of one.  can someone help me with this?

i haven't tried making a reset button, i am hoping to figure that out by looking through the code, but if someone can help with that too that would be great.  i think this is an awesome module, but i did not find many posts on it, and there was not much documentation.
Title: Re: SpinLock Implementation
Post by: Khris on Fri 19/01/2007 06:55:48
SpinLock.SpinRight() will turn the dial even if it is the if-condition.

bool a=SpinLock.SpinRight();  // turn dial

if (a) Display("You figured it out!");


OR remove the first call to SpinRight(), the one before the if.

Implementing a reset button should be simple, just call SpinLock.ResetCombo() in its onClick-code.
Title: Re: SpinLock Implementation
Post by: vjamesv on Sat 20/01/2007 04:24:45
The reset button worked great, and I also put in an exit button.  I still cannot get it to recognize when i have put in the correct combination though.  I have tried both ways you mentioned for the right button:

bool a=SpinLock.SpinRight();
if (a) Display("You figured it out!");

and i also tried:

if (SpinLock.SpinRight()){
  Display("You figured it out!");
}

Both ways, i could spin the lock forever and i never got the combination.  here is what i used to set the combination.  i put this in the room settings to occur after fadein:

SpinLock.InitLock(3,42,8); 
SpinLock.SetCombo(2,1,5);

please help....   thank you
Title: Re: SpinLock Implementation
Post by: Ashen on Sat 20/01/2007 12:06:47
I'm not very familiar with the module (available HERE (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23755.0), for anyone wondering), but what if you ignore that SpinLock.SpinRight should check the combo as well, and directly use SpinLock.CheckCombo yourself?

Since the module's author hasn't been on in over a year, I doubt you'll get any official support on this. Perhaps you could try adding a few Display... commands to the module script, to see where the check is failing?
Title: Re: SpinLock Implementation
Post by: vjamesv on Sat 20/01/2007 19:28:41
well that sucks.  i sent him a message, so we'll see if i can get a response. 

i put in the checkcombo but i still am not getting a response to anything i do.  all i do is sit and spin...

maybe strazer will be able to help me figure it out since it looks like he had a lot of input on the module... 
Title: Re: SpinLock Implementation
Post by: Maverick on Sat 20/01/2007 23:00:28
Ashen

I looked at the code for checkcombo and I have some ideas why it doesn't work but as a noob I would rather reserve my opinion before someone takes my head off.

Vjamesv
I managed to create a little work around if you are interested

Add the following code to the header script

struct SpinLock{
Ã,  import static function InitLock(int obj, int view,Ã,  int max);
Ã,  import static function SetCombo(int a, int b, int c);
Ã,  import static function ResetCombo();
Ã,  import static function SpinLeft();
Ã,  import static function SpinRight();
Ã,  import static function CheckCombo();
Ã,  [color=Red]import static function CheckSolved();[/color]

};

In the main module script add this function above checkcombo

static function SpinLock::CheckSolved(){
if(firstBool == true && secondBoolA == true && secondBoolB == true && currentPosition == thirdNum){
Display("Hoorah");//or whatever caption you want to display
}
Ã, 
}


Add the function above to your SpinRight function in the main module script like this:

static function SpinLock::SpinRight()
{
Ã,  if(firstNum < 0)
{
Ã,  Display("You have not set the combination");

}
Ã,  prevPosition = currentPosition;
Ã,  currentPosition --;
Ã,  if(currentPosition < 0)
Ã,  {
Ã,  Ã,  currentPosition = maxNum;
}
object[obj].SetView(view, 0, currentPosition);
prevDirection = direction;
direction = "right";
[color=Red]SpinLock.CheckSolved();[/color]

if(SpinLock.CheckCombo())
{
Ã,  return true;
}
else
{
Ã,  return false;
}
}


Now you do not need to put the if(Spinlock.SpinRight()) in the room script.
I know that this is not the perfect solutionÃ,  :P (maybe Ashen can clean it up) but I tested it and it works which seems to be the issue here.
Title: Re: SpinLock Implementation
Post by: vjamesv on Sun 21/01/2007 00:00:17
i input all the code you gave me, and when i went to save the room i got this error:

---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was:

In: 'Script header'



Error (line 5): 'SpinLock' is already defined



Do you want to fix the script now? (Your room has not been saved).
---------------------------
Yes   No   
---------------------------



maybe i did not put the struct in the right spot?  i put it in the header script



Title: Re: SpinLock Implementation
Post by: Maverick on Sun 21/01/2007 08:35:42
Where exactly did you put this code?
Did you edit the modules header or create a new header?

I uploaded a demo with the altered module HERE (http://www.2dadventure.com/ags/Spinlock_demo.zip) and the "changed"(Sorry Snake Blisken I just couldn't figure it out) module  HERE (http://http://www.2dadventure.com/ags/Spinlock_module1.zip) . Take a look at the demo and you will see where I added the code. The combination is set for 5,1,3.

I also suggest that you add the following line of code to fix the problem with the final dial only being set properly after the text "Hoorah" has already been displayed.


static function SpinLock::CheckSolved(){
if(firstBool == true && secondBoolA == true && secondBoolB == true && currentPosition == thirdNum){
Wait(5); // THIS IS THE LINE YOU MUST ADD!!!!!!!!!!!
Display("Hoorah");//or whatever caption you want to display
}
Ã, 
}



I hope this helps.

EDIT 6/2/2007
Download file update for demo game (now virus free :-[).
Take note that the wait command is now included i the the CheckSolved function to make sure that the rotation is completed before "Hoorah" (or whatever) is displayed.Ã,  Sorry about the win 32/Hirag.a but my anti virus program did not pick it up (not even when I scanned for it today even though the last update was 27/1/2007) but AVG7 did so I'm sure its fixed.

EDIT 9/2/2007
Uploaded a new module file with the fix.


Title: Re: SpinLock Implementation
Post by: vjamesv on Sun 21/01/2007 15:45:36
yeah i was in the wrong area.  i was using the game's header script and not the module's.  thank you so much for your help!
Title: SpinLock Module: basic help
Post by: AntmanJB on Sun 04/02/2007 05:45:41
Hey, I found a similar thread but it didn't fully answer my questions so I'm just going to ask them myself.
First of all, where do I put the module so AGS can recognise it?
Well actually, what I'm looking for is a step-by-step guide to getting it to work. The readme file was not very clear.
Thanks for any help you can give me.
By the way, it's that Snake Blissken one.
Title: Re: SpinLock Module: basic help
Post by: Khris on Sun 04/02/2007 06:42:06
From the script menu, choose Module manager and import it there.
Title: Re: SpinLock Module: basic help
Post by: vjamesv on Sun 04/02/2007 15:27:23

Yeah the instructions did not help me at all, so it took me a while to figure out how to make it work. 

I made a separate room for this, and i put the graphics in there as separate objects.  Then in the interaction menu for each object, under 'any click on object' i put run script, and then put the script for each object as explained in the readme file there. 

Also, for the settings in the room, when the players enters i put a run script where i ran the SpinLock.InitLock and SpinLock.SetCombo commands. 

Hope that helps get you started.
Title: Re: SpinLock Module: basic help
Post by: AntmanJB on Mon 05/02/2007 05:32:52
Okay, I've managed to do most of it.
I have the room, with the combo as an object using all the different views. The spin left, spin right and reset buttons are all working properly. (Note: the object can't cover those buttons or they won't work, I used hotspots for them.)
The only thing I can't work out is how exactly to use the SpinLock.CheckCombo bit to finish it.
As soon as I do that, my small game will be done! I think I'll post it here if I can, although don't get your hopes up for something great.

Anyway thanks for the help.
Title: Re: SpinLock Module: basic help
Post by: Khris on Mon 05/02/2007 14:53:24
Try this:

// inside spin left/right-button's on_Click
  SpinLock.SpinLeft();/SpinRight();
  if (SpinLock.CheckCombo()) {
    Display("The lock springs open!");
    player.ChangeRoom(5);
  }
Title: Re: SpinLock Module: basic help
Post by: Maverick on Mon 05/02/2007 18:40:43
This question came up a few weeks ago so you can also take a look at  THIS (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=29821.0) thread to help you along.

As for how the spinlock works:

Rotate right till you hit the first number
Rotate left and pass the second number the first time you reach it and go all the way around till you hit it again
Rotate right until you hit the 3rd number and the lock should be open.
QuoteAs soon as I do that, my small game will be done! I think I'll post it here if I can, although don't get your hopes up for something great
By saying post it here I assume you mean in the game release section of the forum and not in this thread because that is a definate no no!



Title: Re: SpinLock Module: basic help
Post by: AntmanJB on Tue 06/02/2007 10:55:46
Okay Maverick, number 1: I already looked at that page and it didn't answer my first questions. That's why I started this post.
Number 2: I know where the finished games go.
Number 3: YOUR EXAMPLE LOCK IN THE OTHER THREAD DOWNLOADED A VIRUS TO MY COMPUTER.
So maybe you should check on that.
Luckily it seems to be a low threat one.
Title: Re: SpinLock Implementation (SOLVED)
Post by: Ashen on Tue 06/02/2007 11:09:24
OK, I'd somehow managed to miss this (second) thread.

AntmanJB, since the questions are closely related I've merged them. As I told vjamesv in another of his threads questions about a specific module really belong in the module's thread, to keep them all together. Keeping them to one thread here is the next best thing :)

Maverick, I also get that virus error - it seems to be in the compiled exe of the test game. Deleting that folder and recompiling seems to get rid of the threat, but you might want to look in to it, as Antman says.
Title: Re: SpinLock Implementation (SOLVED)
Post by: AntmanJB on Tue 06/02/2007 11:16:35
Yeah that's okay that you merged them. Except that now people think my problems has been solved since it says that in the subject line!
I'm still having trouble with the checkcombo.
<SpinLock.SpinLeft();Ã, 
if(SpinLock.CheckCombo()){Display("blah blah")>

That's what I have for SpinLeft, and for SpinRight too.
But whenever I put in the combo, it doesn't end.
I followed the correct directions but it still won't recognise it.
I couldn't seem to follow those earlier suggestions about altering the module's script so any advice would be appreciated.
Title: Re: SpinLock Module: basic help
Post by: Ashen on Tue 06/02/2007 12:20:26
Dang, I thought I'd set it to use your title, sorry about that. I guess now this can stand as the SpinLock help thread, since it seems to have picked up some interest (nothing for a year, then 2 questions in a month!).

Unfortunately, it seems like CheckCombo not working properly is some quirk of how it was coded. Maverick's version fixed that, I think, so if we can get a virus-free version up you should be OK.
Title: Re: SpinLock Module: basic help
Post by: Maverick on Tue 06/02/2007 21:59:17
Holy Sh..! :-[

Updated it so try it again.
Title: Re: SpinLock Module: basic help
Post by: AntmanJB on Wed 07/02/2007 01:30:18
Your demo does work.
But is it just me, or is your updated module just an empty folder? That's all I get when downloading.
Title: Re: SpinLock Module: basic help
Post by: Maverick on Wed 07/02/2007 18:59:26
Quote from: AntmanJB on Wed 07/02/2007 01:30:18
Your demo does work.
I would hope so. The question is..did it help you in any way to solve your problem or answer some of your questions? Do you still need help with this or can we consider this matter solved?

Quote
But is it just me, or is your updated module just an empty folder? That's all I get when downloading.

I just downloaded it and and it seems to be fine.
If anyone else had this problem please pm me.

EDIT:
Uploaded a new file
Title: Re: SpinLock Module: basic help
Post by: AntmanJB on Thu 08/02/2007 02:38:11
Like I said, I'm having trouble with the checkcombo command. Everything else works.
The updated module is still only an empty folder.
Every time I download it it's the same. Nothing inside the zipped folder.

By the way, I went back and looked over the code you suggested and added it to mine, but it still does nothing.
I don't know what's wrong.
Title: Re: SpinLock Module: basic help
Post by: Maverick on Sun 11/02/2007 21:09:24
Quote from: AntmanJB on Thu 08/02/2007 02:38:11
The updated module is still only an empty folder.
Sorry! :-[ Fixed that.
Quote
By the way, I went back and looked over the code you suggested and added it to mine, but it still does nothing.
I don't know what's wrong.
The problem is with the way you set up the sprites. Snake Blisken did not mention it in the module's documentation but the way the module is set up you MUST start your dial at 0 and not one although it is possible to make it work the way you have it i.e. starting from 1. Let's say your code is set up as 1,2,3. To open the safe at run-time your will have to use the code 2,3,4 (add 1 every time to compensate for 0 that is missing).
I trust that this will solve your problem and if it does mark the thread as solved. If it doesn't let me know so I can find a hole to crawl into :P.
Title: Re: SpinLock Module: basic help
Post by: Ashen on Mon 12/02/2007 14:51:15
Antman can't set the topic to solved, since I merged two threads. Post here, though, and I can modify the first one. (Or, leave it unsolved, to be the semi-official thread for any future questions.)

Quote
Let's say your code is set up as 1,2,3. To open the safe at run-time your will have to use the code 2,3,4 (add 1 every time to compensate for 0 that is missing).
That means if you subtract 1 when you set the code, it'll look right in-game? So, setting the code to "0,1,2" means the player has to enter "1,2,3" to open the lock. (Right? I'm just testing my understanding here, to make the post slightly more on-topic  :P)
Title: Re: SpinLock Module: basic help
Post by: Maverick on Mon 12/02/2007 17:53:35
Quote from: Ashen on Mon 12/02/2007 14:51:15
Antman can't set the topic to solved, since I merged two threads. Post here, though, and I can modify the first one. (Or, leave it unsolved, to be the semi-official thread for any future questions.)
Received an E-mail from Antman and his problem is solved but we can leave this open.
Quote
That means if you subtract 1 when you set the code, it'll look right in-game? So, setting the code to "0,1,2" means the player has to enter "1,2,3" to open the lock. (Right? I'm just testing my understanding here, to make the post slightly more on-topicÃ,  :P)
That is correct Mr moderator Sir :-[
Title: Re: SpinLock Module: basic help
Post by: Ashen on Mon 12/02/2007 18:37:00
Cool, I'm just trying to pick the original module apart and see what makes it work. Or 'not work', as the case seems to be...

It's a nice idea, it's just a shame it's being so problematic.