problem with IF statement (Solved)

Started by Maslak791, Thu 14/03/2013 19:02:03

Previous topic - Next topic

Maslak791

Hello!

I was trying to find solution for my problem on your forum, but i've failed.
Anyway, I have some trouble with my code. I want to make the character to pick up item form shelf and say what he has found, but if he already has it i just want him to say that theres nothing here. Here's what I've come up with:


function hSzafka_Interact()


{
 
if (player.HasInventory(iCoins))
{
Display("There's nothing here");
}


 
else{
     player.Walk(323, 486, eBlock
     player.AddInventory(iCoins)
     Display("I found some coins")
     }

}

It's giving me this error while compiling- "room1.asc(-10): Runtime error: unexpected eof"

PS. Sorry for my English, I was trying my best

Andail

#1
Learn to use proper indentation, it will help you check if there's an { too few (or too many).
So, your code is
Code: ags

function hSzafka_Interact()
    {
    if (player.HasInventory(iCoins))
        {
        Display("There's nothing here");
    }
    else{
        player.Walk(323, 486, eBlock
        player.AddInventory(iCoins)
        Display("I found some coins")
    }
}


Found a missing ";" at line 9 and 10! They're hard to spot, the little buggers :)

Khris


Maslak791

Wow, It's working perfectly! Thank you very much! This is programming at its finest haha

Cerno

Also maybe an idea for an alternative implementation.

You write that the character should comment that there is nothing there after picking up the coins.

I wonder how it currently works in your game. I am guessing that you do it somewhat like this:

- If the coins are there, you hover your mouse over them and the text "A bunch of coins" appears.
- After you pick them up, you hover your mouse over the spot where the coins were and again the message "A bunch of coins" appears.
- When you try picking them up again the character says "There is nothing there"

If it is like that I would suggest the following:
- Add a coins object to the scene
- When the player picks up the coins, you make the object invisible and switch off the hotspot

That way, after picking up the coins they won't be visible in the scene and when you hover over the spot where they were, nothing happens (because there is nothing there)
123  Currently working on: Sibun - Shadow of the Septemplicon

Stupot

@Cerno It depends if there is actually a clickable item or if the player is acquiring the item by searching some shelves (or a cupboard etc) where you might not necessarily see the object on screen.

If the latter is the case, then I think mazlak has the right idea, because he still wants the player to be able to search the shelf and return a message, even if there is nothing useful left on the shelf.
MAGGIES 2024
Voting is over  |  Play the games

Cerno

Right, I was assuming a lot here. Possibly too much. ;)
123  Currently working on: Sibun - Shadow of the Septemplicon

Khris

Quote from: Maslak791 on Thu 14/03/2013 20:53:19
Wow, It's working perfectly! Thank you very much! This is programming at its finest haha
Not really; if the player can lose the item but still visit the room with hSzafka, they can get the coins over and over again.
A quick way to resolve this is using Game.DoOnceOnly():

Code: ags
function hSzafka_Interact() {
  if (Game.DoOnceOnly("find coins")) {
    player.Walk(323, 486, eBlock);
    player.AddInventory(iCoins);
    Display("I found some coins");
  }
  else Display("There's nothing here");
}

Maslak791

@Cerno
There are no visible coins for the player other then ones in the inventory :). Player gets coins from interacting with hSzafka (Szafka means cupboard in polish, btw. :)).
Also, I know this is not the right thread to ask but could you briefly explain how to make text appear when players cursor hovers over the item? I was playing around with "Moves mouse over hotspot" the text appears in the middle of screen and it disappears only if player clicks the mouse

@Khris
This will surely come in handy :).

Khris

Quote from: Maslak791 on Wed 20/03/2013 11:56:43Also, I know this is not the right thread to ask but could you briefly explain how to make text appear when players cursor hovers over the item?
Asked and answered dozens of times already. Use the search function and look for cursor text or something like that. Also don't used threads older than two or three years.

SMF spam blocked by CleanTalk