Hi guys!
I'm a newcomer here in the AGS world and I need help :(
It's the first time I try to start an empty game and I want to create a mouse interface similar to the Broken Sword one.
So I'm writing a prototype where the left mouse button is for "walk"/"interact" and the right mouse button for "look at".
Here's the code I wrote in the GlobalScript.asc (I found this script in a tutorial)
function on_mouse_click (MouseButton button)
{
{
if (IsGamePaused() == 1)
{
}
if (player.ActiveInventory == null)
{
if (button == eMouseLeft)
{
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing)
{
ProcessClick(mouse.x, mouse.y, eModeWalkto);
}
else
{
ProcessClick(mouse.x, mouse.y, eModeInteract);
}
}
else if (button == eMouseRight)
{
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing)
{
}
else
{
ProcessClick (mouse.x, mouse.y, eModeLookat);
}
}
else if (player.ActiveInventory != null)
{
if (button == eMouseLeft)
{
ProcessClick(mouse.x, mouse.y, eModeUseinv);
}
else if (button == eMouseRight)
{
player.ActiveInventory = null;
}
}
}
}
}
It seems all right, but when I try to perform a "Look at" action, the character doesn't do anything at all (the "interact" action works nice).
I tryed to change the "Look at" with the "interact" in that script to try if there were any problem with the mouse, and it works well.
Thank you guys :) Sorry for my English :P
There's a BASS template released recently, that may do what you want: http://www.adventuregamestudio.co.uk/forums/index.php?topic=48441.0 (may save you some time)
On your problem, did you make a LookAt event handler function for your character(s) same way as you did Interact handler functions?
I apologize for double post, there's something I did not notice in your script at first examination.
Now I clearly see you have a mismatching brackets issue, and your condition blocks are messed up.
First, there's extra opening bracket you do not need, at line 3 (I am refering to line numbers in your posted code, obviously, not the ones you have in actual script).
Then, you forgot to put a closing bracket for "else if (button == eMouseRight)" block. Just add a closing bracket between lines 31 and 32.
This mistake is probably a result of bad indentation at certain places in your code, you just need to align the text everywhere and you will easily see what's wrong.
Thank you Wizard :)
I made all the corrections you suggested, but the "Look At" action still doesn't work :(
I'll paste you the code for the actions as I wrote in the room script
Interact script:
function hHotspot1_Interact()
{
cPescio.Say ("It's broken."); //THIS ACTION WORKS IN GAME
}
"Look at" script:
function hHotspot1_Look()
{
cPescio.Say ("It's a ladder."); //IT DOES NOTHING :(
}
Thank you for the BASS template :) I will study it :)
You may change it and it may work (at least I think so...). Look at this (your script):
else if (button == eMouseRight)
{
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing)
{
}
else
{
ProcessClick (mouse.x, mouse.y, eModeLookat);
}
}
Instead, try this:
else if (button == eMouseRight)
{
if (GetLocationType(mouse.x, mouse.y) == eLocationLocationHotspot || GetLocationType(mouse.x, mouse.y) == eLocationLocationCharacter || GetLocationType(mouse.x, mouse.y) == eLocationLocationObject)
{
ProcessClick (mouse.x, mouse.y, eModeLookat);
}
}
Be sure to tell me if this helps. Its the only solution I can think of.
Thank you Adeel, but it still doesn't work :(
Now I have this piece of code :(
function on_mouse_click (MouseButton button)
{
if (IsGamePaused() == 1)
{
}
if (player.ActiveInventory == null)
{
if (button == eMouseLeft)
{
if (GetLocationType(mouse.x, mouse.y) == eLocationNothing)
{
ProcessClick(mouse.x, mouse.y, eModeWalkto);
}
else
{ if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot || GetLocationType(mouse.x, mouse.y) == eLocationCharacter || GetLocationType(mouse.x, mouse.y) == eLocationObject )
{ ProcessClick (mouse.x, mouse.y, eModeInteract);
}
}
}
else if (button == eMouseRight)
{
{
if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot || GetLocationType(mouse.x, mouse.y) == eLocationCharacter || GetLocationType(mouse.x, mouse.y) == eLocationObject )
{ ProcessClick (mouse.x, mouse.y, eModeLookat);
}
}
}
else if (player.ActiveInventory != null)
{
if (button == eMouseLeft)
{
ProcessClick(mouse.x, mouse.y, eModeUseinv);
}
else if (button == eMouseRight)
{
player.ActiveInventory = null;
}
}
}
}
There is one extra set of brackets I noticed. Remove it like this and try again.
else if (button == eMouseRight)
{
if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot || GetLocationType(mouse.x, mouse.y) == eLocationCharacter || GetLocationType(mouse.x, mouse.y) == eLocationObject )
{
ProcessClick (mouse.x, mouse.y, eModeLookat);
}
}
Does it work?
I resolved -_-
I had to associate the events in the hotspot panel, in the room page... I didn't know it was necessary... I told you I am a noob! :P
Anyway, thank to you both! In any case I learned a lot! :)
Quote from: ultralooca on Mon 24/06/2013 14:07:49
I resolved -_-
I had to associate the events in the hotspot panel, in the room page... I didn't know it was necessary... I told you I am a noob! :P
Anyway, thank to you both! In any case I learned a lot! :)
I thought about that part too. I were going to ask you this but I had to go then. Good job on figuring this out for yourself. And Yes, it
IS necessary. To simplify and shorten the things, you may also use this:
else if (button == eMouseRight)
{
if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
{
ProcessClick (mouse.x, mouse.y, eModeLookat);
}
}
So tell me, does it work or am I being optimist?
Quote from: Adeel S. Ahmed on Mon 24/06/2013 16:13:59
if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
I approve this code :D.
Yea! It works and it's soooooooo clean :)
Thanks again!
Quote from: Crimson Wizard on Mon 24/06/2013 16:57:36
Quote from: Adeel S. Ahmed on Mon 24/06/2013 16:13:59
if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
I approve this code :D.
Thank you very much, sir (laugh).
Quote from: ultralooca on Mon 24/06/2013 17:07:28
Yea! It works and it's soooooooo clean :)
Thanks again!
My pleasure. Off topic but Ah, that feeling you get from helping someone for the first time 8-) I am becoming experienced now :P
BTW, ultralooca, it would be nice if you add "Solved:" at the start of your thread's title, not necessary though.
Done ;)
You are quick, man! 8-0
Ahahah (laugh) if I only could be that fast coding... I can't wait to see my creation taking form :P
I hope I can show you something soon :)
Quote from: ultralooca on Tue 25/06/2013 09:15:31
Ahahah (laugh) if I only could be that fast coding... I can't wait to see my creation taking form :P
Be as slow as you like and take your time. I have learned that one hour taken in the scripting a small script is
FAR better than two hours of debugging a fast written script, trying to locate what went wrong. :X
Quote from: ultralooca on Tue 25/06/2013 09:15:31
I hope I can show you something soon :)
I would love to see your creation.