Game Maker - Turn On/Off Sound - button

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.

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]))

How do I restart the current room to what it was when the player entered it?

While making a game, I had set it up so when the player dies, the game resets. Feeling this was a bit too harsh, I did some research and found the room_restart() code, which is meant to restart the current room. But, when I input it and triggered it via dying, it did not reset the room to how it was. How do I reset it?
{
room_restart()
}
That is the code that triggers on collision with an enemy.
You would have to record the state somehow. Game Maker has a native state save function, but if you wanted a room to stay the same without changing the player's inventory or something, you'd have to manually record the state of every object in it so when the player leaves and comes back, everything resumes where it was.
You could try having each object record important variables to a file with sections for each room. For instance, you could use a JSON file with sections for each room, and each object would record their vital data into that section. For example:
{
"rmHouse": {
"Mom": {
"x": 64,
"y": 128,
"action": "lookingDown"
}
}
}
Check around for Game Maker JSON extensions. Here's one for GM8.1/Studio: http://gmc.yoyogames.com/index.php?showtopic=565659
room_goto(room);
That will send the room back to how it was when you first entered it, but room_restart should do the same.
Make sure that you do not have "persistent" checked in the room options. That's what sounds like it's probably the issue to me.
If you had
if(health = 0) {
instance_destroy();
}, then delete instance_destroy. Replace it with x = 32
y = 64
health = max_hp
restart_room();
so that the X position is set, the Y position is set, the health is back, and the room restarts.

Record audio into mutil-small block each duration with getUserMedia

I think I should begin with an example of what I want:
User allow the web page to access mic, then start recording.
Every 3 seconds (for example) capture what the user say (maybe into an Blob).
Repeat until user want to stop.
I've found many example that use AudioContext.createScriptProcessor but it work by given a buffer size, I love to have similar thing but given a duration.
you can simply use recorderjs, and use it in the below mentioned fashion:
var rec = new Recorder(source);
rec.record();
var recInterval = setInterval(function(){
rec.exportWAV(function(blob){
rec.clear();
// do something with blob...
});
}, 3000); // 3000 - to get blob for every three seconds.
later on some button click, add rec.stop() to end .

Adding Removing Columns to Datagrid in Flex with States

I was developing an app that in the first state you choose a date range using dataFields then you press a button to go to another state and generate a datagrid showing an employee list and another scrollable datagrid with its columns generated dynamically having the worked hours for every employee in every date.
The step sequence to get the error message is:
You choose a date range for example: from 01/01/2013 to 01/31/2013
You press generate button (The app change the currentState = "EmployeeList" and all is OK)
You press the back button (you return to initial state and all is OK)
If you change the date range having more days than before date range then all is OK
If you change the date range having less days than before date range then next error is reached
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.controls.dataGridClasses::DataGridBase/http://www.adobe.com/2006/flex/mx/internal::columnHeaderWordWrap()
at mx.controls.dataGridClasses::DataGridItemRenderer/validateProperties()
at mx.managers::LayoutManager/validateClient()
at mx.controls.dataGridClasses::DataGridHeader/updateDisplayList()
at mx.core::UIComponent/validateDisplayList()
at mx.managers::LayoutManager/validateDisplayList()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
and if you google it then some results take to visit apache bug reporting site
https://issues.apache.org/jira/browse/FLEX-22108
And there is no more...
But I found how to solve it!
To solve it first of all I was googling a lot and i looks like no one got this error and I discover that is a Flex Bug reported to Apache. And I was analyzing the original code from DataGrid.as and DataGridColumn.as to think about a possible solution and I was making some tests and nothing work.
What I did and I hope it will be useful to someone
when you click the back button, inside the backbutton_clickEventLister() and before currentState="";
I just set columns array to new Array();
protected function bttnBack_clickEventHandler(event:Event) : void {
// This code line solved it
dtGrdWorkedHours.columns = new Array();
// Make sure of code it before state change stament
currentState = "";
}

Resources