random message every x seconds but to stay on screen for a few seconds - random

I have a program where I am displaying a message every x seconds (the message pops up), is there a way for the message to stay a little bit on the screen, because there is no time for the user to read it properly.
your guidance is much appreciated.
below is a piece of my code where I am using millis().
if (millis() - timer >= 4000) //random message every 4 seconds
{
if(user11.equals(rev_film1[0]))
{
app.text(user11, 15,490);
app.text(rat_film1[0] + " / 10",100,550);
timer = millis();
}
else if(user11.equals(rev_film1[1]))
{
app.text(user11, 15,490);
app.text(rat_film1[1] + " / 10",100,550);
timer = millis();
}
else if(user11.equals(rev_film1[2]))
{
app.text(user11, 15,490);
app.text(rat_film1[2] + " / 10",100,550);
timer = millis();
}
else if(user11.equals(rev_film1[3]))
{
app.text(user11, 15,490);
app.text(rat_film1[3] + " / 10",100,550);
timer = millis();
}
}

Think about how you would know when to show and hide the square. What is the value of timer when you want to show and hide the square? What is the value of millis()?
Write out a few examples of timelines, something like this:
millis = 0: program start
millis >= 4000: show message
millis >= 6000: hide message
Then use this timeline as a guide for when you want stuff to happen, and map this to the variables in your sketch.
If you're having trouble, please post a MCVE (not your entire sketch, but not a disconnected snippet either) in a new question post and we'll go from there. Good luck.

Related

Game maker death codes which will run when you collide with a skeleton don't work like It should

p_hp is health variable and o_skeleton is our enemy. What I want to do is to kill the player when it collides with the skeleton 3 times, but it seems It doesn't work.
What did I do wrong?
p_hp=3;
if(place_meeting(x,y,o_skeleton))
{
p_hp=p_hp-1
}
if(place_meeting(x,y,o_skeleton)) && (p_hp==0)
{
instance_destroy(self);
}
Please help to solve my issue.
Is p_hp = 3 declared in the Step Event? then that means each time it reached that code, p_hp will reset back to 3. And the Step Event is called each frame.
I recommend declaring variables that'll change later on in the Create Event.
Also, It's better to use this to check if your character is still alive:
if (p_hp <= 0)
{
instance_destroy(self);
}
That way it doesn't need to collide to check if it's still alive, and if the chance happens that p_hp is lower than 0. It will still be destroyed.
Keep in mind, this possible results in the player dying instantly to the skeleton, because it's checking the Step Event each frame. In that case, you'll need to look into a short invincibility time after getting hit.
Adding invincibility after getting hit:
There are multiple ways to add invincibility, the method I use is to add invincibility would be making an invincibility variable and use that as a timer. give it a value the moment it's hit, and let it return to 0 over time. you should also add the check if the invincibility value is higher than 0;
So, in practise:
Create Event:
p_hp = 3;
invicibility = 0;
Step Event:
if (invincibility > 0) //timer in step event
{
invincibility -= 1/room_speed // (1/room_speed) = real time seconds
}
if (place_meeting(x,y,o_skeleton) && invincibility <= 0) //avoids getting hit while invincibility has value.
{
p_hp -= 1;
invincibility = 0.5; //grants half a second of invincibility after getting hit
}
if (p_hp <= 0)
{
instance_destroy(self);
}
(And as extra tip: p_hp -= 1 does the same as p_hp = p_hp - 1)

Code is getting slower with every run (PowerPoint VSTO)

I'm writting a PowerPoint AddIn (VSTO) which makes the following (very roughly):
1. Loop through all slides
2. Loop through all tags for each slide and write the tag information to a List-Object
3. Do some calucations on the List-Object and update some columns in the list-Object
4. Loop through the List-Object and write the tags back to the sorresponding slides / tags
I recognized that this code runs for every run slower and slowwer - the 10th run is 3-4 times slower than the first one.
I also see the memory usage goes up for every run.
What are my tools to check where the bottle neck is?
How can I find the problem which makes my code slower for every run?
Is there a way to clear the memory etc. the AddOn uses after each run?
I'm sorry to ask such general question, but please let me know if you need more details
My PowerPoint has 32 Slides - for each slide i want to write tags (in this example 49 Tags). Because of updates etc. the code is executed several times by the user. I simulate this by doing it 11 times automatically. I recognize here the same behavior as by user interaction: the writing of the tags for the 32 Slides is getting slower with every execute.
I reduced my code to the minimum which has the same behavior. I tried also to first delete the tags on every slide but without success.
private void btn_DoIt10Times_Click(object sender, EventArgs e)
{
Stopwatch watch = new Stopwatch();
watch.Start();
SlideTags_Write();
watch.Stop();
//MessageBox.Show("Time spend: " + watch.Elapsed);
for (int i = 1; i <= 10; i++)
{
SlideTags_Write();
}
Stopwatch watch2 = new Stopwatch();
watch2.Start();
SlideTags_Write();
watch2.Stop();
MessageBox.Show("Time 1st run: " + watch.Elapsed + "\n Time 11th run: " + watch2.Elapsed);
}
public void SlideTags_Write()
{
PowerPoint.Presentation oPresentation = Globals.ThisAddIn.Application.ActivePresentation;
foreach (PowerPoint.Slide oSlide in oPresentation.Slides)
{
//for (int iTag = 1; iTag <= oSlide.Tags.Count; iTag++)
//{
// oSlide.Tags.Delete(oSlide.Tags.Name(iTag));
//}
for (int iTag = 1; iTag < 50; iTag++)
{
oSlide.Tags.Add("Tag_" + iTag.ToString(), "Tag Value " + iTag.ToString());
}
}
}

Timer Efficiency

I'm working on an AS3 project and for one of the effects I use timers to switch the colors then stop. The function is below.
//global variable
private var valueAnimationTimer:Timer = new Timer(50);
//constructor
valueAnimationTimer.addEventListener(TimerEvent.TIMER, scrollUp );
//function
private function scrollUp(e:TimerEvent):void
{
var i:int = e.currentTarget.currentCount as int;
if (i < 10)
{
if (colored){
if (i % 2 == 0){
ChangeColor(ico, flickerColor);
}
else{
ico.transform.colorTransform = new ColorTransform();
}
}
tfValue.y -= 7.5;
}
else
{
RemoveFilters(ico);
tfValue.y = ico.height / 2;
e.currentTarget.reset();
RemoveSprite(tfValue);
colored = false;
}
}
Each character (object) has it's own version of this function and it happens at different times (like when it is injured or poisoned). The listener is added once in the constructor, it is only removed when the character dies and is removed from the stage. The issue here is after the timer is used on at least 3 characters, the frame rate begins to drop. Every time the function is called, the frame rate drops lower and lower.
What I don't understand is, if the timer is stopped, and the listeners are only added once so it doesn't overload the stack, then why does the frame rate begin to decline after the listener is actually used? It doesn't run forever only for a small amount of time, but it happens again and again. When the frame rate drops the entire program begins to lag badly and eventually freezes. I have no idea what is causing this
Also be aware that inside of the Timer function, the first number is your count in MILLISECONDS and the second is repeat count
var fl_TimerInstance:Timer = new Timer(240000, 1);
So this example above is a 4 minute timer that repeats 1 time
I bring this up because yours is set for 50 milliseconds which is very quick lol

Graphically showing remaining time

Let's consider a user has t milliseconds to make a click, 0 < t < 5000. We'd like to show graphically how much time is left. Let's assume that the user has to click the button once again within t.
property int startTime
property int fps: 40
property int t: 1000 // for example
Button
{
id: btn
text: "Click me!"
onClicked:
{
text = "Click again!"
startTime = new Date().getTime()
timer.restart()
}
}
Timer
{
id: timer
interval: 1000 / fps
onTriggered:
{
var progress = (new Date().getTime() - startTime) / t
if (progress < 1)
{
pb.value = progress
restart()
}
else
{
pb.value = 1
btn.text = "Try again"
}
}
}
ProgressBar
{
id: pb
value: 0
}
I'm only worried about the performance impact. The UI should always remain accesible and react quickly to the tap, since t can be low. If it weren't, the user could click the button within the set time but "lose", since the application wouldn't respond to the click.
Should I worry about the performance hit? Is there any option to avoid it? I expect my application to be run on low-end devices too.
I'm using Qt on Android
If fps is reasonable, then I think that performance won't be an issue and the UI will remain responsive.
Anyway I think it is much more elegant to achieve the same result using an animation... You can use a NumberAnimation to continuously update the value of the progress bar, and then start the animation when you want to start counting the time left...

Lap timer in XNA 4.0?

Right, I've got a slight problem here, in which I've attempted to implement a lap timer.
In my protect override void update I've got this;
if ((IntersectPixels(destinationRedRect, car2redTextureData, startingLineRectangle, startingLineTextureData)))
{
{
redHit = true;
_timer1 += gameTime.ElapsedGameTime.TotalMilliseconds;
}
}
What I'm saying here^ is, if car2red is colliding with the starting line, the timer begins, but if it's not, timer does not add seconds (it just stops_ . How can I make it so, if car2red hits the startingLine and moves forward a few pixels (without touching starting line) the timer still continues?
Thank you.
You should have a separate if statement like this:
if (redHit) {
_timer1 += gameTime.ElapsedGameTime.TotalMilliseconds;
}
if ((IntersectPixels(destinationRedRect, car2redTextureData, startingLineRectangle, startingLineTextureData)))
{
redHit = true;
//Only use this line if you want to reset the timer to 0 when the player crosses that line again.
_timer1 = 0;// I'm assuming that _timer1 is a double
}

Resources