How To Make An Int Score on Another Page in Xcode - xcode4

I am trying to make an int on another page for my game. I tried This:
"score = score + 1;"
"scoretext.text = [NSString stringWithFormat:#"%i", score];"
But every time I switch out of that view controller and come back the score is at Zero! How do you save the Number so when you come back it is not gone!

i think you should have a look at user defaults in objective C so that you can save the data for local user game even when the game is sent to background you can have track to the score or also you can store the current user state
you can have a look at this in the links below
How do I save user preferences for my iPhone app?
http://www.idev101.com/code/Objective-C/Saving_Data/NSUserDefaults.html

Related

Hi, I need an algorithm to tell a sprite to change the image when the in-game text finishes appearing (in GameMaker studio 1.4)

I need an algorithm to tell a sprite to end as soon as the text finishes appearing, basically I need to make a cutscene which describes the beginning of a story within the game, but since I'm using gamemaker, I don't know how to do it, can someone help me?
For cutscenes and automated image sequences you usually have some sort of variables, that handle the states and counters for displaying sprite's sub-images.
But firstly I like to use mainly two main time-related variables in my controller object usually named sys (counter and counterTime):
c = 0; // and for stepEvent: c += 1; // so it goes +1 per step
ct = 0; // and for stepEvent: ct+= 1 / room_speed; // so it goes +1 per second
During the cutscene you might want to stop everything else that moves:
is_cutscene = false; // objects might not be able to move when this is true
// you still have to implement that by yourself
// player can't move if is_cutscene, nothing happens!!
(except cutscene buttons etc...)
So now when the player gets to a 'cutscene'y object and triggers some cutscene_1 = true eg. you can have the image/text/sound/animation object come to life/create/active... That object might have in the create event:
duration = 6; // 6 seconds the scene lasts
start_time = sys.ct // and in Step: if sys.ct > (start_time + duration)
// then -> cutscene advance/destroy
Ofcourse - this is super simple and now you could only say implement:
walk close to a pop-up object
show an image for 6 seconds
it dissappears
And it might not be big trouble to implement it... BUT THIS may also be the foundation for more advanced multi-step sequence and cuts.

How to add time widget/picker?

New appmaker user here.
I'm trying to port the work permits approval "app" I made with G Suite form+spreadsheet+GAS; users should enter the day, the start and end time of the permit.
I can see from the Forum Sample that the Date field type is a DateTime field type, so I can use it in my model.
The problem is I cannot find the time picker in the widgets, and the date box has no option to also enter the time.
Am I missing something?
Time Pickers for App Maker
I read your question and thought I'd try to role one of my own and this is what I came up with. I put all of the buttons on a pageFragment and call it with app.showDialog(app.pageFragments.timePicker2);
I only use clientside script.
function updateOutput(){
var h=app.pageFragments.TimePicker2.properties.hour||'00';
var m=app.pageFragments.TimePicker2.properties.minute||'00';
var s=app.pageFragments.TimePicker2.properties.second||'00';
var t=h + ':' + m + ':' + s;
app.pageFragments.TimePicker2.descendants.timeLBL.text=t;
return t;
}
function updateHour(v){
app.pageFragments.TimePicker2.properties.hour=v;
updateOutput();
}
function updateMinute(v){
app.pageFragments.TimePicker2.properties.minute=v;
updateOutput();
}
function updateSecond(v){
app.pageFragments.TimePicker2.properties.second=v;
updateOutput();
}
Here's what my time picker looks like:
Yes. Adding all of the buttons is a nuisance but there are a few features about AppMaker that make it more tolerable.
First you can assign the TimePicker form properties which I use as global properties. I had three hour,minute and second.
Then after you add all of the hour buttons you can grab all of them at one time by clicking each one while holding down control on a windows machine and click on the onClick event and pick custom action and type this in updateHour(widget.text); the code completion won't give you text as an option but type it any way.
I just figured out how to grab the buttons all a one time by pushing shift and selecting with the mouse
Do the same thing with the minute and second buttons using updateMinute(widget.text) and updateSecond(widget.text); This saves you a lot of time typing all of the functions into each widget control panel. Also you don't have to bother giving all of the buttons special names like I did.
But you might like to format them with the following css.
And again you can grab all of the buttons at one time and change the following setting:
That way you can style all of the buttons at one time.
My save button just copies the final string into a label on the main panel.
app.pages.Testing.descendants.timeLBL2.text=app.pageFragments.TimePicker2.descendants.timeLBL.text;
app.closeDialog();
You will probably want to do something more elegant.
Here's a demo: in preview mode. Sorry about the 24 hour clock. I always use this for my own stuff because it's so much easier and I like it. You'll probably want AM & PM. I'll probably go back and do that too.
For an AM/PM Picker I used these functions:
function updateOutputAP(){
var h=app.pageFragments.TimePicker3.properties.hour||'00';
var m=app.pageFragments.TimePicker3.properties.minute||'00';
var s=app.pageFragments.TimePicker3.properties.second||'00';
var ap=app.pageFragments.TimePicker3.properties.ap||' ';
var t=h + ':' + m + ':' + s + ' ' + ap;
app.pageFragments.TimePicker3.descendants.timeLBL.text=t;
return t;
}
function updateHourPM(v){
app.pageFragments.TimePicker3.properties.hour=v;
app.pageFragments.TimePicker3.properties.ap='PM';
updateOutputAP();
}
function updateHourAM(v){
app.pageFragments.TimePicker3.properties.hour=v;
app.pageFragments.TimePicker3.properties.ap='AM';
updateOutputAP();
}
function updateMinuteAP(v){
app.pageFragments.TimePicker3.properties.minute=v;
updateOutputAP();
}
function updateSecondAP(v){
app.pageFragments.TimePicker3.properties.second=v;
updateOutputAP();
}
And this is what my picker looks like:
Now that I know how to pick the components easily with the mouse it was a break to make this change.
Three AppMaker Time Pickers:
At this time App Maker doesn't provide out of the box Time or Date/Time picker widgets, it means that you need to implement one by yourself. There are at least two ways to accomplish this task:
App Maker way
Wait and hope when App Maker will introduce Time or Date/Time picker widget or use existing App Maker widgets to emulate Time Picker. Calendar Sample can be a good starting point:
Hack into DOM/JS
If you have no concerns about cross-browser compatibility and you are OK to get you hands dirty with DOM manipulation by javascript, creating events listeners and other cool stuff, then you can play with HTML widget and native date/time or time input, or even some third party library.
One simple option would be to simply use a textbox and set the validation in the model field.
You can update your Date object on save or just use as is depending on your application. You get the benefit of auto validation errors in the UI to guide your user and it takes only seconds to set up.
Regex:
\b((1[0-2]|0?[1-9]):([0-5][0-9]) ([AaPp][Mm]))

Game Maker - Turn On/Off Sound

What I have
I have two rooms: rm_home and rm_options. I have a sound: snd_Bgm. And, I have three objects: obj_bgm, obj_BtnOnClicked, and obj_BtnOffClicked.
What I want is very simple
Player can turn on/off the snd_Bgm.
What I have done
In obj_bgm, I have these events:
Create Event: set var global.sound to 1
Room Start: stop sound snd_Bgm; if global.sound == 1 then play sound snd_Bgm
In obj_BtnOnClicked, I have these events:
Left-Pressed Event: play sound snd_Bgm; set var global.sound to 1
In obj_BtnOffClicked, I have these events:
Left-Pressed Event: stop sound snd_Bgm; set var global.sound to 0
I put obj_BtnOnClicked, and obj_BtnOffClicked in rm_options, which can be accessed from rm_home. Then, I put obj_bgm in rm_home.
This is the problem
When game start, it will show rm_home and plays the snd_bgm. I go to rm_options, then click the obj_BtnOffClicked to turn off the sound, so the sound is off. But, when I go back to rm_home, the sound is on again.
What I think
I shouldn't put Create Event: set var global.sound to 1 in obj_bgm, because when rm_home start, it takes the value of var global.sound from Create Event. But, if I put Create Event in obj_BtnOnClicked or obj_BtnOffClicked, it shows a Get Error.
What should I do? Please explain your answer. Thanks.
Are your rooms and your variables persistent ?
If rm_home is not persistent, it will restart every time you leave it. So every object placed in that room will be reset, including obj_bgm, which sets your sound variable to 1. I think this is the reason the sound restarts when you come back to rm_home.
If you still want to reset the room but not this particular object, you can make it persistent. You can do it either by ticking the box in the object or through code.
If you put the create event in a button object, it will not be read until you go to the options room. So when the obj_bgm tries to set it to 1, it does not exist yet. I believe it causes the error.
I make these remarks on assumptions, but I would need to see your code or your error message to help you further.

Progress bar in a Rails app for parser

I made the rails app that parses one website. I wonder, whether it is possible to show the process of the parsing in a progress bar which will be shown on a main page(to start the process you need to click the button)? I think I need to use bootstrap for view of progress bar, but how to pass the process of execution itself into view of bar?
Edit:
The parser itself is situated in the model that stores result to the database after each step i. e. if parser detects first company and its data - save, then the second company and so on. The progress bar will show result based on information from database(I don't understand how to use ajax for this) and I really want to use bootstrap progress bar, not jquery bar.
My model-parser
class PrintingHouses < ActiveRecord::Base
require 'mechanize'
agent = Mechanize.new
page = agent.get('http://www.print-index.ru/default.aspx?p=84&gr=198')
sum=0
loop do
page.search('.goodname .goodname').each do |n|
link = Mechanize::Page::Link.new(n, agent, page)
new = link.click
name = new.search('#ctl00_ctl00_BaseCentralRegion_CentralRegion_lblGoodName h1')
address = new.search('.address')
phone = new.search('.phone')
email = new.search('.email')
website = new.search('.www')
PrintingHouses.create(name: name.text.center(100), address: address.text.strip,
phone: phone.text.strip, email: email.text.strip,
website: website.text.strip)
end
num = page.search('.goodname .goodname').count
sum=sum+num
break unless link = page.link_with(:text => " ยป " )
page = link.click
end
puts sum
end
This question is marked as a duplicate but I didn't find anything that could help me so please help.
The gem Progress Job looks promising for providing progress updates on background jobs. At this time it looks like it works with DelayedJob.

Measuring goals for users who have never logged into my site before

I have a web app. The home page has two main actions:
Sign up to the application
Log into the application
I have a goal set up for sign-ups. I am trying to track the goal conversion rate of users who have never logged into the application before.
The problem I have at the moment is that the conversion rate is being skewed by users who are visiting the homepage simply to log in.
Is there a simple way of doing this?
Thanks very much,
Ben
For the kind of tracking you are looking for, there should be some coding on both your system and Google Analytics.
First, I would recommend you place into your system the intelligence to know the number of log-ins the user has made (As an example, a counter on your database).
Now, to implement that, you will need to set a Custom Var in Google Analytics in a visit level, to segment the users from the non-users, in that CustomVar, you can store both the user ID and the number of logins he has made.
This is the on the login page:
Your Code Should Look Like:
_gaq.push(['_setCustomVar',
1,
'Member Login',
'NUMBER OF LOGINS', // SET THIS FROM YOUR SYSTEM
2 //VISIT LEVEL Custom Var
]);
Remember that this code should go before tracking the pageview.
After setting this up, you should use Advanced Segments to check those specific users, one case could be: (Using the example above)
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : .*
This will give you all the never-loged user access.
Something else you could do is set up Adv Segments to check on a specific number of logins
Setup an Advanced Segment that "Excludes" the Custom Variable (Key 1) - Mathing RegExp : [^1]
This will give you all the users that loged-in more than once.
You can find more info on Custom Vars here.

Resources