I'm trying to make an achievement for when a player have looked at four different objects once.
I'm thinking there must be an easier way. This is how i do it atm, bools for every "look", is there another more efficient way?
else if(Verbs.UsedAction(eGA_LookAt)) {
player.Say ("That's Coda!");
if (Nukeus_Item_4==false)
{
All_Nukeus++;
Nukeus_Item_4=true;
}
if (All_Nukeus==4)
{
gNukeus.Visible=true;
gNukeus.TweenTransparency(0.1, eEaseLinearTween, eNoBlockTween);
aPickupsound.Play();
Wait(120);
gNukeus.TweenPosition(0.5, 220, 250,eBlockTween);
Nukeus_Achievement=4;
}
You can use a Set, everytime add the item name to the Set, if the Set length is equal to 4, roll the achievement.
Or just add to your All_Nukeus int, once the player has looked at the item (use a DoOnceOnly, so it'll only add once). Then check if the int has reached 4. ;) No need for bools in this case.
Quote from: Cassiebsg on Thu 15/09/2022 17:28:00
Or just add to your All_Nukeus int, once the player has looked at the item (use a DoOnceOnly, so it'll only add once). Then check if the int has reached 4. ;) No need for bools in this case.
HAH! I knew it! Thanks! I was thinking about that one! Alltho Set sounds more interesting to me, since i need to learn some more coding then the absolute basics. I knew about DoOnceOnly, i just didn't remember the exact syntax. I typed Doonce but got no help from pushing f1 (laugh)
It's a static method, the syntax is Game.DoOnceOnly("unique string here"). For each string it returns true the first time, then false for each subsequent call.
Also that achievement code looks like you can probably move that into a function.
This is what i've tried. I get the error "undefined Symbol "NukeSet". Defining it outside of the four functions feelt right, but no.
function room_Load()
{
Set* NukeSet = Set.Create();
}
function oCoda_AnyClick() //One of the four functions that's supposed to "add" a item that's been looked at.
{
NukeSet.Add("Coda");
if (NukeSet.Contains("Test") && NukeSet.Contains("Whip") && NukeSet.Contains("Coda"))
{
Display("Achievement Done Test");
}
}
}
You need this:
Set* NukeSet;
function CheckAll()
{
if (NukeSet.Contains("Test") && NukeSet.Contains("Whip") && NukeSet.Contains("Coda"))
{
Display("Achievement Done Test");
}
}
function room_Load()
{
if (NukeSet == null) NukeSet = Set.Create();
}
function oCoda_AnyClick() //One of the four functions that's supposed to "add" a item that's been looked at.
{
NukeSet.Add("Coda");
CheckAll();
}
Edit: fixed room_Load code, thanks CW
I should perhaps mention that the above code creates a new Set each time player enters the room. Is this a correct intention?
EDIT: oh, it's fixed now.
and here i'd thought all i needed to add was a bool == false in the if statement and it would work, but unfortunaly that does not work. This is how i did it, but it's not the right way of course.
Thanks for the help as always, Khris.
function CheckAll()
{
if (NukeSet.ItemCount==4) //For unknown reason when adding && All_Nukeus==false this if statement won't run. Same with "main if statement"
{
//All_Nukeus=true;
NukeSet.Add("Extra"); //Without this added item..I can't make it work without the message repeating itself.
Display("Achievement Done Test");
}
}
Quote from: AndreasBlack on Sun 02/10/2022 16:02:26and here i'd thought all i needed to add was a bool == false in the if statement and it would work, but unfortunaly that does not work. This is how i did it, but it's not the right way of course.
It's hard to tell why it did not work without seeing the exact code you used.
But besides a bool variable, you could also use DoOnceOnly here.
Setting the bool is not enough, you also need to check it.
bool nukeus_achieved = false;
function CheckAll() {
if (NukeSet.ItemCount == 4 && !nukeus_achieved) {
nukeus_achieved = true;
// this will only run once
Display("Achievement Done Test");
}
}
Crimson Wizard, i used the identical code to Khris example, just added the itemcount instead of various && Set.Contains :)
Khris, Thanks again ever so much!