Advertisement

c++ Where are my mistakes

Started by December 26, 2016 09:10 AM
4 comments, last by frob 8 years ago
Ok so here is some info about the code. Im trying to set up a timer on a particular effect. On the unreal engine. the language is c++ and no this is not homework. I was reading some documents from unreal engine about timers and i was trying to set it up and i dont know where i have made my mistakes. I have try re reading the doc to see where i may have made my mistakes but cant find it. I have also done some google searches to see if any one has ask the same question with similer code. also ples excuse my bad English.
// Fill out your copyright notice in the Description page of Project Settings.
#include "Test_1.h"
#include "Countdown.h"
// Sets default values
ACountdown::ACountdown()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
CountdownText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("CountdownNumber"));
CountdownText->SetHorizontalAlignment(EHTA_Center);
CountdownText->SetWorldSize(150.0f);
RootComponent = CountdownText;
CountdownTime = 3;
}
// Called when the game starts or when spawned
void ACountdown::BeginPlay()
{
Super::BeginPlay();
UpdateTimerDisplay();
GetWorldTimerManager().SetTimer(CountdownTimerHandle, this, &ACountdown::AdvanceTimer, 1.0f, true);
}
// Called every frame
void ACountdown::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void ACountdown::UpdateTimerDisplay()
{
CountdownText->SetText(FString::FromInt(FMath::Max(CountdownTime, 0)));
}
void ACountdown::AdvanceTimer()
{
--CountdownTimer;
UpdateTimerDisplay();
if (CountdownTime < 1)
{
//Countdown is done, Stoping timer.
GetWorldTimerManager().ClearTimer(CountdownTimerHandle);
//Perform any special actions we want to do when the timer ends.
CountdownHasFinished();
}
}
void ACountdown::CountdownHasFinished()
{
//Change to a speacial readout
CountdownText->SetText(TEXT("GO!"));
}

The only question is "where are my mistakes", followed by a bunch of code.

Please review the forum's rules, in particular:

  • Before you post, make sure you have tried every option you can with respect to figuring out the problem yourself. Be prepared to answer the question (proactively, ideally) "what have you tried to solve the problem yourself?"
  • Be as descriptive as you can; state the language, platform, compiler, et cetera that you are using, as relevant.
  • Do not ask homework related questions, they will be closed on sight.

With the rules in mind, some questions so we can attempt to help you:

  1. This looks a lot like homework, but since it is Christmas break it is far less likely to be homework. Is it homework?
  2. Why are you asking about mistakes? What kind of mistakes are you looking for?
  3. What do you think is wrong? Why?
  4. What do you think needs fixing? Why?
  5. What have you already tried that didn't work?
  6. What kind of response do you think will be helpful?

Otherwise we could say things like there is an error on line 37, or you should be using some pattern or idiom, but without knowing those details nobody know what you are really fishing for.

Advertisement

It is also helpful to show your code with proper indenting, it makes reading code a whole lot simpler.

There is a "<>" code environment available in the editor for preserving indents.

The only question is "where are my mistakes", followed by a bunch of code.

Please review the forum's rules, in particular:

  • Before you post, make sure you have tried every option you can with respect to figuring out the problem yourself. Be prepared to answer the question (proactively, ideally) "what have you tried to solve the problem yourself?"
  • Be as descriptive as you can; state the language, platform, compiler, et cetera that you are using, as relevant.
  • Do not ask homework related questions, they will be closed on sight.

With the rules in mind, some questions so we can attempt to help you:

  1. This looks a lot like homework, but since it is Christmas break it is far less likely to be homework. Is it homework?
  2. Why are you asking about mistakes? What kind of mistakes are you looking for?
  3. What do you think is wrong? Why?
  4. What do you think needs fixing? Why?
  5. What have you already tried that didn't work?
  6. What kind of response do you think will be helpful?

Otherwise we could say things like there is an error on line 37, or you should be using some pattern or idiom, but without knowing those details nobody know what you are really fishing for.

Ok thank you. and sorry if i did not explain my self i am still new to this type of stuff.

Ok thank you. and sorry if i did not explain my self i am still new to this type of stuff.

You've edited your post to include some new information, but you still haven't said what isn't working.

I recognize this as a tutorial for timers, so I would suggest going through each single line and double checking that there isn't a difference somewhere.

Hello to all my stalkers.

The edit is better, but still not enough to help solve the issue.

I'm curious why you are taking that approach. There are many options, like using a blueprint timer with your own function applied, or using one of the ticking functions like Tick or TickComponent or any of the various other events if they're appropriate, such as pre- or post- physics.

Whatever you end up doing with it, you'll still need to refine your question a little to explain what problem you are actually experiencing, and what you expect to have happen, and what you have tried.

Also, you should probably include the declaration from the header.

This topic is closed to new replies.

Advertisement