How to count how many times checked if answer correct "Swift" - swift

I am trying a tutorial on how to do a number guessing game in Swift and we have where you put a number in a field and click a button to guess. If you are wrong a message appears and if you are right a different message appears. I would like to count how many times someone tried to answer the question and if they get to 5 times trying I would like to reply with a message like you stink at this (kidding)"Don't give up!" or whatever. Is there a way to count how many times someone has clicked that button. I see some similar posts but nothing that helps..

Declare a variable var count:Int = 0
And then every time you click the button, where you check is it match, add
count = count + 1
and then see when you gonna reply them the message, use if else
if count == 5{
// Any message
}

Related

how to write a text and calculation in a same time like Calcnote app in Flutter

I try lots of things but I failed kindly help me with how to do this and please someone shares a complete. I also share a screenshot of the original app I making same like this app.
App description:
1:When typing or calculating on the app if the user needs the next line and show a list num
2: The most important thing is when we calculate any num can we write something in the same type ( you think it's a notepad + calculator)?
3: Also when we write and type 5 + 5 we don't need to press = equal to. they abstract and subtract automatically.
thank you so much for your support.

Why does my Roblox joining badge not work?

I made a visiting or thanks for joining badge that I made to be given to any new person that joins my game, but it only works sometimes.
I couldn't try anything, the badge gave it to 60 people when 146 people joined! All 146 people were supposed to get it!
This is the badge code:
local badgeID = 2124446943
local badgeService = game:GetService("BadgeService")
function onEntered(player)
wait(1)
if not badgeService:UserHasBadge(player.UserId, badgeID) then
badgeService:AwardBadge(player.UserId, badgeID)
end
end
game.Players.PlayerAdded:Connect(onEntered)
It was supposed to be given to all the people who visited. Because at some point they were all new!
It is an unlikely possibility that only 60 unique people have played your game, but all of them played your game at least twice resulting in 146 visits
Another possibility is that some players disconnect before the wait(1) in your function, so maybe try this:
function onEntered(player)
repeat wait(0.1) until player ~= nil
if not badgeService:UserHasBadge(player.UserId, badgeID) then
badgeService:AwardBadge(player.UserId, badgeID)
end
end
end
But I don't think that'll have any effect because the player can't be nil if they've entered... (idk it's a random suggestion don't count on me)
Sorry I wanted to comment instead of typing here but I need 50 reputation to do so

How can I get statements within functions to execute in a randomly chosen order?

I'm relatively new to Matlab, and I've been trying to solve my problem for ages but I'm just continuously arriving at a dead end.
I have a code which should, in theory, play 3 sounds in a random order (each order being different for each trial). Upon each sound playing the participant will be asked which sound they heard and then given feedback. I have all the code complete and working up until the random order part. I have created code that on each trial will randomly order 1,2 and 3.
Order = [1, 2, 3];
PhonemeOrder = randperm (numel(Order));
I then have a function which plays the sound/asks the questions etc. within this I have attempted switch cases statements and if else statements depending on the number that PhonemeOrder produces but the order doesnt change even when phoneme order does. I believe my problem is however that PhonemeOrder comes out like [1,2,3] or [3,1,2] which is what i wanted. but Im not sure how to get my sounds to play in the order that it shows because I am using code like...
if/ PhonemeOrder = 1;
then do this...
elseif phonemeorder = 2;
then do this...
else
do this...
Or I've tried code like
switch cases
case 1
do this
case 2
do this
case 3
do this
I'm guessing this is where i am going wrong, but i just dont know how to change it and make it work! I hope this makes sense? I just need it to play in the order that phonemeorder specifies, with the order changing on each trial.
Any help will be greatly appreciated :D
bexG,
I think you are on the right track.
The only thing you need is to use a "for-loop" to go through the array of PhonemeOrder.
for i=1:length(PhonemeOrder)
switch PhonemeOrder(i)
case 1
play the first song
case 2
play the second song
case 3
play the thrid song
end
end
I hope this will help.
Please let me know if you have any further question.

email reminders time driven google spread

Can anyone help.
I have a simple google spreadsheet that enables me to book delegates onto a variety of courses at different venues and at different times and dates.
I used the same spreadsheet last year, kindly set up by Bob Rashkin! It worked perfectly and sent emails when delegates booked onto the course and also sent email reminders automatically when the course was 9 days or so from starting.
I have duplicated the spreadsheet for this term but the sheet refuses to send the reminder emails, I really could do with a little help on this?
A secondary matter is that when the script sends a booking confirmation email, it sometimes sends two of them which creates a lot of phone calls asking if they've booked on twice.
Help someone please
This is the reminder script that I'm using
function Reminder() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var s=ss.getActiveSheet();
var r1=s.getDataRange().getRow()+1;//Start past the header row!!! Doh!
var r2=s.getDataRange().getLastRow();
var mn,m,days,d=new Date(),coursedate=new Date(),dlen=8.64e7,i,course,r,year;//8.64e7
var subject="Just a gentle reminder that you or colleague(s) from your setting have a Paediatric First Aid course coming up in the next week or so. ";
var recipient, body, tail="Please be aware that Entrust (formerly Staffs Early Years) will make a charge for non attendance so";
tail+=" please make sure that you familiarise yourself with the times and dates of the course. ";
tail+="If you need help finding the venue then please follow the link below to find the venue and print off a map if required.";
tail+="\n\nhttp://www.blithfieldsafety.co.uk/venues/";
for (r=r1;r<=r2;r++) {
recipient=s.getRange(r,9).getValue();
course=s.getRange(r, 2).getValue();
body=subject+"\nCourse Details\n"+course+"\n\nDelegate Name: "+s.getRange(r,4).getValue()+"\n\n"+tail; //changed (r,2) to (r,4)
mn=course.match(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/)[0];
m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"].indexOf(mn);
days=course.match(/(\d{1,2})(st|nd|rd|th)/g);
year=d.getFullYear();
for (i in days) {
coursedate.setMonth(m);
coursedate.setDate(days[i].slice(0,-2));
if ((coursedate-d)/dlen<14 && s.getRange(r,16).getValue()!="mail sent") {
GmailApp.sendEmail(recipient, subject, body);
s.getRange(r,16).setValue("mail sent");//arbitrarily picked col 15
}
}
}
};
It looks like the time remaining until the course begins is checked with this line:
if ((coursedate-d)/dlen<14 && s.getRange(r,16).getValue()!="mail sent") {
That line is making a date calculation, and checking if the value of a cell had the text "mail sent" in it. If the cell didn't have mail sent AND the date calculation is true, then an email gets sent. Notice that the divisor dlen is a value that was hard coded.
var mn,m,days,d=new Date(),coursedate=new Date(),dlen=8.64e7,i,course,r,year;//8.64e7
The value of the variable dlen is set to a constant value of 8.64e7. But I'm guessing that the math no longer works right for some reason.
The value of dlen is 86400000.
There are 24 hours in a day, 60 minutes in an hour, and 60 seconds in a minute.
24 * 60 * 60 = 86,400 seconds in a day. So, obviously, the 86,400,000 number is a multiple of the number of seconds in a day.
I'm guessing that there is a new course every month?
You can add a Logger.log() statement to your code, and run it so see what the variable values are:
Logger.log('coursedate: ' + coursedate);
If you put that line in your code:
for (i in days) {
coursedate.setMonth(m);
Logger.log('coursedate: ' + coursedate);
coursedate.setDate(days[i].slice(0,-2));
Logger.log('coursedate: ' + coursedate);
Logger.log('d: ' + d);
if ((coursedate-d)/dlen<14 && s.getRange(r,16).getValue()!="mail sent") {
That would tell you what the values of the variables coursedate and d are right when the calculation is being made.
Then you could hopefully figure out why the math is the way it is. To view the Logger.log() output, click on the View menu, and choose the Logs menu item. A list of logged values will be in the window.

Messagebox.show fires twice after button click (MVVM)

I am using Galasoft MVVMLight. I have a button bound to a command which sends a message to the view to display a messagebox asking for confirmation. If I click either the Yes or No on the messagebox it performs the necessary actions then shows up again. However if I step through the program instead I only get the messagebox once. Is this a bug or is something else going on?
EDIT: I modified the messagebox.show line by adding an Icon and default result and now I can't reproduce this behavior... I'm stumped... if it happens again I'll try a counter like airplaneman19 suggested.
Try tracking the amount of times the MessageBox shows up with an integer, like so:
int counter = 0;
if(counter == 0){
MessageBox.Show();
counter++;
}
else if (counter == 1)
/*Do something that won't alter the program just to escape the if....else statement
like "x++";
I had a similar problem once, I mean, with MessageBox firing twice. It was due to focus changes, and ListView in WinForms fired another selection changed event when running the app; but when debugging - some focus change was missing, and there was no bug :)
I hope this atleast gives you some ideas...