cannot change background during game play gamemaker? - game-maker

I use this on event create to change background during game play. But won't change the background, any idea?
seconds = current_second;
if seconds < 30
{
background_index[0] = background0;
background_visible[0] = true;
}
if seconds > 30
{
background_index[5] = background5;
background_visible[5] = true;
}
// Set background
background_hspeed[0] = -2;
background_hspeed[5] = -2;

I don't understand your goal, so a few examples:
Example 1.
Create event:
background_index[0] = background0;
background_index[1] = background1;
Step event:
seconds = current_second;
if seconds < 30
{
background_visible[0] = true;
background_visible[1] = false;
}
else
{
background_visible[0] = false;
background_visible[1] = true;
}
Example 2. Same, but using alarm
Create event:
background_index[0] = background0;
background_index[1] = background1;
event_perform(ev_alarm, 0);
Alarm 0 event:
seconds = current_second;
if seconds < 30
{
background_visible[0] = true;
background_visible[1] = false;
}
else
{
background_visible[0] = false;
background_visible[1] = true;
}
alarm[0] = room_speed * 30;
Example 3. Other idea...
Create event:
background_index[0] = background0;
background_index[1] = background1;
background_visible[0] = true;
background_visible[1] = true;
event_perform(ev_alarm, 0);
Alarm 0 event:
seconds = current_second;
if seconds < 30
{
background_index[0] = background0;
background_index[1] = background1;
}
else
{
background_index[0] = background1;
background_index[1] = background0;
}
background_x[0] = 0;
background_x[1] = 0;
background_hspeed[0] = 0;
background_hspeed[1] = -2;
alarm[0] = room_speed * 30;
If you need to change backgrounds many times then you need use step event or alarms, because create event does it only once. Also when you use scrolling, you need remember that after some time x position of the background will be outside a screen, so you can't see background (except cases when your background is tiled).

Related

Run a Google Script only weekdays every 15-minute, between certain hours - using time-based trigger?

Hi I have a google app script that I need to run every weekday only between 09:30 AM to 15:45 PM. I am not being able to add the minutes. I have a code that has the hours in it. My code is given below. I tried to add minutes with && but that is giving funny results.
function Record() {
var today = new Date();
var day = today.getDay();
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
if(day == 6 || day == 0) {
return;
} else {
var hour = today.getHours();
var minute = today.getMinutes();
if(hour < 10 || hour > 15) {
return;
}
var ss1 = SpreadsheetApp.getActiveSpreadsheet();
var source1 = ss1.getRange("Nifty!C28:K28");
var destSheet1 = ss1.getSheetByName("Record 1");
destSheet1.appendRow(source1.getValues()[0]);
var ss2 = SpreadsheetApp.getActiveSpreadsheet();
var source2 = ss2.getRange("Bank Nifty!C28:K28");
var destSheet2 = ss2.getSheetByName("Record 2");
destSheet2.appendRow(source2.getValues()[0]);
}
}
Can anyone help me out?
This is not exactly the time but it's pretty close
function Record(e) {
if (e['day-of-week'] < 6 && e.hour > 9 && e.hour < 16) {
const ss1 = SpreadsheetApp.getActive();
const src1 = ss1.getRange("Nifty!C28:K28");
var dsh1 = ss1.getSheetByName("Record 1");
dsh1.appendRow(src1.getValues()[0]);
var ss2 = SpreadsheetApp.getActiveSpreadsheet();
var src2 = ss2.getRange("Bank Nifty!C28:K28");
var dsh2 = ss2.getSheetByName("Record 2");
dsh2.appendRow(src2.getValues()[0]);
}
}
//only creates one trigger for the handlerfunction
function createTimeBasedTrigger() {
if (ScriptApp.getProjectTriggers().filter(t => t.getHandlerFunction() == "Record").length == 0) {
ScriptApp.newTrigger("Record").timeBased().everyMinutes(15).create();
}
}

Auto Update DropDown items in Datalist in Asp.net

I am Working on a Shop page where I want the Dropdownlist show the available Quantity . (Eg: if stock contains 2 items then Dropdownlist contains Items 1 followed by 2..)
Here's the code I attempted , I have no idea in which event i should put it.
`
Code:
connect cu = new connect();
System.Web.UI.WebControls.Label Label8 = (System.Web.UI.WebControls.Label)DataList1.FindControl("modelnoLabel");
//Modelnolabel contains model no
cu.cmd.CommandText = "select qty from stock where modelno=#mod";
//qty is retrived based on modelnolabel text of datalist
cu.cmd.Parameters.Clear();
cu.cmd.Parameters.AddWithValue("#mod", Label8.Text);
int qty = Convert.ToInt16(cu.cmd.ExecuteScalar());
if (qty < 5 && qty > 0)
{
(DataList1.FindControl("DropDownList1") as DropDownList).Items.Clear();
for (int i = 1; i < qty + 1; i++)
{
(DataList1.FindControl("DropDownList1") as DropDownList).Items.Add(Convert.ToString(i));
}
}
else
{
(DataList1.FindControl("DropDownList1") as DropDownList).Visible = false;
}`
Thanks in advance
Thanks for the silence ,It really helped me figure out on my own :)
protected void DataList1_Load(object sender, EventArgs e)
{
for(int j=0;j<DataList1.Items.Count;j++)
{
System.Web.UI.WebControls.Label Label8 = (System.Web.UI.WebControls.Label)DataList1.Items[j].FindControl("modelnoLabel");
connect cu = new connect();
cu.cmd.CommandText = "select qty from stock where model=#mod";
cu.cmd.Parameters.Clear();
cu.cmd.Parameters.AddWithValue("#mod", Label8.Text);
int qty = Convert.ToInt16(cu.cmd.ExecuteScalar());
if (qty <= 5 && qty > 0)
{
(DataList1.Items[j].FindControl("DropDownList1") as DropDownList).Items.Clear();
for (int i = 1; i < qty+1; i++)
{
(DataList1.Items[j].FindControl("DropDownList1") as DropDownList).Items.Add(Convert.ToString(i));
(DataList1.Items[j].FindControl("qtylab") as System.Web.UI.WebControls.Label).Text = "Only "+qty+" Left";
(DataList1.Items[j].FindControl("qtylab") as System.Web.UI.WebControls.Label).ForeColor = Color.OrangeRed;
(DataList1.Items[j].FindControl("Button1") as System.Web.UI.WebControls.Button).Visible= true;
(DataList1.Items[j].FindControl("Button3") as System.Web.UI.WebControls.Button).Visible= true;
}
}
else if (qty > 5)
{
(DataList1.Items[j].FindControl("DropDownList1") as DropDownList).Items.Clear();
for (int i = 1; i < 6; i++)
{
(DataList1.Items[j].FindControl("DropDownList1") as DropDownList).Items.Add(Convert.ToString(i));
(DataList1.Items[j].FindControl("qtylab") as System.Web.UI.WebControls.Label).ForeColor = Color.GreenYellow;
(DataList1.Items[j].FindControl("qtylab") as System.Web.UI.WebControls.Label).Text = "Available";
(DataList1.Items[j].FindControl("Button1") as System.Web.UI.WebControls.Button).Visible = true;
(DataList1.Items[j].FindControl("Button3") as System.Web.UI.WebControls.Button).Visible= true;
}
}
else
{
(DataList1.Items[j].FindControl("DropDownList1") as DropDownList).Visible = false;
(DataList1.Items[j].FindControl("qtylab") as System.Web.UI.WebControls.Label).Text = "Out of Stock";
(DataList1.Items[j].FindControl("qtylab") as System.Web.UI.WebControls.Label).ForeColor = Color.Red;
(DataList1.Items[j].FindControl("Button1") as System.Web.UI.WebControls.Button).Visible= false;
(DataList1.Items[j].FindControl("Button3") as System.Web.UI.WebControls.Button).Visible = false;
(DataList1.Items[j].FindControl("Label1") as System.Web.UI.WebControls.Label).Visible = false;
}
}
}

Recording Sound with recorderWorker.js and recorder.js

I am using recorderWorker.js and recorder.js
The final output which i get from this code is 44.1khz, 2-channel (stereo) wav file.But my requirement is 8khz , 1-channel wav file.
How can i achieve this with the help of recorderWorker.js
Kindly help me to resolve the issue.
The code for recorderWorker.js is
var recLength = 0,
recBuffers = [],
sampleRate;
this.onmessage = function(e){
switch(e.data.command){
case 'init':
init(e.data.config);
break;
case 'record':
record(e.data.buffer);
break;
case 'exportWAV':
exportWAV(e.data.type);
break;
case 'getBuffer':
getBuffer();
break;
case 'clear':
clear();
break;
}
};
function init(config){
sampleRate = config.sampleRate;
}
function record(inputBuffer){
var bufferL = inputBuffer[0];
var bufferR = inputBuffer[1];
var interleaved = interleave(bufferL, bufferR);
recBuffers.push(interleaved);
recLength += interleaved.length;
}
function exportWAV(type){
var buffer = mergeBuffers(recBuffers, recLength);
var dataview = encodeWAV(buffer);
var audioBlob = new Blob([dataview], { type: type });
this.postMessage(audioBlob);
}
function getBuffer() {
var buffer = mergeBuffers(recBuffers, recLength)
this.postMessage(buffer);
}
function clear(){
recLength = 0;
recBuffers = [];
}
function mergeBuffers(recBuffers, recLength){
var result = new Float32Array(recLength);
var offset = 0;
for (var i = 0; i < recBuffers.length; i++){
result.set(recBuffers[i], offset);
offset += recBuffers[i].length;
}
return result;
}
function interleave(inputL, inputR){
var length = inputL.length + inputR.length;
var result = new Float32Array(length);
var index = 0,
inputIndex = 0;
while (index < length){
result[index++] = inputL[inputIndex];
result[index++] = inputR[inputIndex];
inputIndex++;
}
return result;
}
function floatTo16BitPCM(output, offset, input){
for (var i = 0; i < input.length; i++, offset+=2){
var s = Math.max(-1, Math.min(1, input[i]));
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
}
}
function writeString(view, offset, string){
for (var i = 0; i < string.length; i++){
view.setUint8(offset + i, string.charCodeAt(i));
}
}
function encodeWAV(samples){
var buffer = new ArrayBuffer(44 + samples.length * 2);
var view = new DataView(buffer);
/* RIFF identifier */
writeString(view, 0, 'RIFF');
/* file length */
view.setUint32(4, 32 + samples.length * 2, true);
/* RIFF type */
writeString(view, 8, 'WAVE');
/* format chunk identifier */
writeString(view, 12, 'fmt ');
/* format chunk length */
view.setUint32(16, 16, true);
/* sample format (raw) */
view.setUint16(20, 1, true);
/* channel count */
view.setUint16(22, 2, true);
/* sample rate */
view.setUint32(24, sampleRate, true);
/* byte rate (sample rate * block align) */
view.setUint32(28, sampleRate * 4, true);
/* block align (channel count * bytes per sample) */
view.setUint16(32, 4, true);
/* bits per sample */
view.setUint16(34, 16, true);
/* data chunk identifier */
writeString(view, 36, 'data');
/* data chunk length */
view.setUint32(40, samples.length * 2, true);
floatTo16BitPCM(view, 44, samples);
return view;
}
You don't need to modify the Recorder.JS library - this functionality is already provided. The constructor accepts a config object as the second parameter, as below:
var audioContext = new AudioContext();
var microphone = audioContext.createMediaStreamSource(stream);
recorder = new Recorder(microphone, { numChannels: 1, sampleRate: 8000 });

j script runtime error: object requiered

I am working on the platform confirmit, which creates online surveys. This is a script node that results in the runtime error "object required", I would be grateful if you could help me fix it.. It is supposed to check whether certain codes hold 1 or 2 in the questions q2b and q3a (questions are referenced with the function f() - f(question id)[code]) - the
'//skip ?' part. Then it recodes a maximum of four of the codes into another question (h_q4) for further use.
var flag1 : boolean = false;
var flag2 : boolean = false;
//null
for(var i: int=0; i <9; i++)
{
var code = i+1;
f("h_q4")[code].set(null);
}
f("h_q4")['95'].set(null);
//skip ?
for(var k: int=1; k <16; k+=2)
{
var code = k;
if(f("q2b")[code].none("1", "2"))
flag1;
else
{
flag1 = 0;
break;
}
}
if(f("q3a")['1'].none("1", "2"))
flag2;
if(flag1 && flag2)
f("h_q4")['95'].set("1");
//recode
else
{
var fromForm = f("q2b");
var toForm = f("h_q4");
const numberOfItems : int = 4;
var available = new Set();
if(!flag1)
{
for( i = 1; i < 16; i+=2)
{
var code = i;
if(f("q2b")[i].any("1", "2"))
available.add(i);
}
}
if(!flag2)
{
available.add("9");
}
var selected = new Set();
if(available.size() <= numberOfItems)
{
selected = available;
}
else
{
while(selected.size() < numberOfItems)
{
var codes = available.members();
var randomNumber : float = Math.random()*codes.length;
var randomIndex : int = Math.floor(randomNumber);
var selectedCode = codes[randomIndex];
available.remove(selectedCode);
selected.add(selectedCode);
}
}
var codes = fromForm.domainValues();
for(var i = 0;i<codes.length;i++)
{
var code = codes[i];
if(selected.inc(code))
{
toForm[code].set("1");
}
else
{
toForm[code].set("0");
}
}
}
the first part of the code (//null) empties the 'recepient' question to ease testing
.set(), .get(), .any(), .none() are all valid

ActionScript 2 character selection

I haven't been able to make a character selection in ActionScript 2 so what is an example that, if I click on this button, a movieclip comes out in this frame?
Frame 1:
movieClip1.alpha = 0;
movieClip1.stop();
movieClip2.alpha = 0;
movieClip2.stop();
movieClip3.alpha = 0;
movieClip3.stop();
button1.onPress = function() {
movieClip1.alpha = 100;
movieClip1.play();
}
button2.onPress = function() {
movieClip2.alpha = 100;
movieClip2.play();
}
button3.onPress = function() {
movieClip3.alpha = 100;
movieClip3.play();
}
try something like the below. I haven;t tested this so it prob won;t compile but it'll be very close. Basically put this on a single empty frame on the main timeline. make sure you have button and character movieclips all with export settings and linkage identifiers set. Modify code below and see what happens.
var numButtons:Number = 10; //number of buttons you want
var buttonMovieClipName:String = "button"; //linkage identifier of button
var startX:Number = 10; //start x position
var startY:Number = 500; //start y position
var dist:Number = 10; //distance between buttons
var characters:Array = {"A","B","C","D"}; //linkage names of your characters
var currentChar:MovieClip = null;
for(var i:Number = 0; i < numButtons; i++)
{
this.attachMovie("button", "button"+i, this.getNextHighestDepth());
this["button"+i]._x = startX + (i*(dist+this["button"+i]._width]));
this["button"+i]._y = startY;
this["button"+i].character = characters[i];
this["button"+i].onPress = displayCharacter;
}
function displayCharacter():void
{
var par = this._parent;
//remove previous character on stage
if(currentChar != null)
{
removeMovieClip(par[currentChar]);
}
par.attachMovie(this.character, this.character, par.getNextHighestDepth()); //atach character
par[this.character]._x = 400; //set to whatever
par[this.character]._y = 300; //set to whatever
currentChar = this.character; //set current character to this
}

Resources