Collecting enough points to proceed

Started by Blondbraid, Mon 07/11/2016 16:39:29

Previous topic - Next topic

Blondbraid

Hi!
I want to try and make make a game where the player must first click on a number of items in order to proceed.
Basically, they have to click on a high number of things, and then interact with a character, but if they haven't interacted with enough items, interacting with the character will only lead to a message that they haven't collected enough things.

Is there any form of Global variable I can use to add a number to a meter (invisible to the player) or similar whenever the player interacts with a crucial item,
and the script for character only takes effect once the number is high enough?

Cassiebsg

Uhm... sure, just make an int and default it to zero ... :-D Then add +1 to every thing the player needs to do, and check if int == 10 (or whatever value you want.
There are those who believe that life here began out there...

Blondbraid

Quote from: Cassiebsg on Mon 07/11/2016 16:43:55
Uhm... sure, just make an int and default it to zero ... :-D Then add +1 to every thing the player needs to do, and check if int == 10 (or whatever value you want.
Ok, How do I add +1 in the script? I keep getting errors and I don't know how it's supposed to be written...

Cassiebsg

Code: ags

int something=0; //just to illustrate, as you want this to be a global variable
something++;  // like this? 
There are those who believe that life here began out there...

Blondbraid

Quote from: Cassiebsg on Mon 07/11/2016 17:08:07
Code: ags

int something=0; //just to illustrate, as you want this to be a global variable
something++;  // like this? 

I tried writing something++; but just keep getting error messages.

Cassiebsg

Maybe copy/pasting the error msg would be a good idea? (nod)
There are those who believe that life here began out there...

Blondbraid

Quote from: Cassiebsg on Mon 07/11/2016 17:30:06
Maybe copy/pasting the error msg would be a good idea? (nod)
Code: ags
function hHotspot1_Interact()
{
something++;
}

Failed to save room room1.crm; details below
room1.asc(5): Error (line 5): Expected ';'

Here is the error, I'm not sure what's wrong since there is a ; there.

Crimson Wizard

#7
How and where did you declare "something" variable?

You need to have it declared above first use.

Also, it is much easier to create a variable in the Global Variables panel (from project tree), because when you do that in script you need to keep imports/exports in mind if you want to use same variable in multiple rooms.

Blondbraid

Quote from: Crimson Wizard on Mon 07/11/2016 17:43:20
How and where did you declare "something" variable?

You need to have it declared above first use.

Also, it is much easier to create a variable in the Global Variables panel (from project tree), because when you do that in script you need to keep imports/exports in mind if you want to use same variable in multiple rooms.
I just made a int variable in the Global Variables, and set the value to zero. I tested using int something=0; at the start of the first room but then I got:
room1.asc(26): Error (line 26): Already referenced name as import; you must define it before using it

Cassiebsg

You never answer what line 5 in room1 is. ???
There are those who believe that life here began out there...

Blondbraid

Quote from: Cassiebsg on Mon 07/11/2016 18:14:27
You never answer what line 5 in room1 is. ???
Line 5 in room 1 was
Code: ags
something++;
The same code I added in the post with the error message, should have specified that more.

Crimson Wizard

#11
Quote from: Blondbraid on Mon 07/11/2016 18:10:39
Quote from: Crimson Wizard on Mon 07/11/2016 17:43:20
Also, it is much easier to create a variable in the Global Variables panel (from project tree), because when you do that in script you need to keep imports/exports in mind if you want to use same variable in multiple rooms.
I just made a int variable in the Global Variables, and set the value to zero. I tested using int something=0; at the start of the first room but then I got:
room1.asc(26): Error (line 26): Already referenced name as import; you must define it before using it

Do you have this "something" variable also declared manually in the global or room script? Because if you created it in Global Variables, you need to remove its declaration from other places.

In other words, you either declare it in script yourself, but do so before using it (setting or getting its value ever in scripts), OR you declare it in Global Variables pane, but then you obviously do not need to declare it in script.

Cassiebsg

That seems odd. 8-0
Could you try and delete the line and just write another line of code?  Like Display("This");

Just to see if it throws the same error?
There are those who believe that life here began out there...

Blondbraid

Quote from: Crimson Wizard on Mon 07/11/2016 18:34:27

Do you have this "something" variable also declared manually in the global or room script? Because if you created it in Global Variables, you need to remove its declaration from other places.

In other words, you either declare it in script yourself, but do so before using it (setting or getting its value ever in scripts), OR you declare it in Global Variables pane, but then you obviously do not need to declare it in script.
I have removed the declaration from the room script and I'm able to start the game now, but I still don't understand how I should add +1.

Crimson Wizard

You add something to variable like this:

Code: ags

something = something + 1; // long elaborate way
something += 1; // shorter way
something++; // this only works with 1, you cannot ++++ for 2 or ++++++ for 3


Where you put this code depends on when do you want this value to increase. For example, on hotspot click, like you tried to do earlier.

Blondbraid

It works now, thank you both for your help! ;-D

I'm also wondering if there are a way to ensure that the +1 only happens once so that the player cannot spam one single hotspot,
how can I disable the function after one use per hotspot?

Khris

Code: ags
function hHotspot_Interact()
{
  if (Game.DoOnceOnly("some arbitrary but unique text")) {
    // interaction code here
    something++;
    ...
  }
  else Display("You already did that.");
}

Blondbraid

Thank you, it worked on the first try! :)

SMF spam blocked by CleanTalk