Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


bls61793

Member Since 07 Jul 2011
Offline Last Active Jul 15 2012 09:12 AM

Posts I've Made

In Topic: (C++ Beginner) I hate to post here, but... why won't my "if" stat...

15 July 2012 - 09:14 AM

Thanks... XD I knew I would feel dumb at the end of this one... always the little things.

Appreciate it. Sometimes it's just helpful to have someone else look at it.

In Topic: Anyone Here Know Anything About UnrealScript?

12 July 2011 - 01:05 PM


Hello guys.

I've only made a few posts here while I was (well, I'm still in the process of practicing) learning C++.

I have since made the jump to using the Unreal Development Kit for my game projects. So far the Syntax is very similar to C++ which is helpful; however, I'm having a little problem

Note: The reason I havn't posted to the Unreal Forums is that my account is currently not active and i am waiting in a Moderator Queue to allow me onto the forums.

So I was wondering if anyone here knows Unreal Script and would be willing to answer a question I have.


In C++ class functions and members can be accessed by the member operator '.'

This seems to not be the case with unreal script.

I'm trying to figure out how to call class member functions and access class members in Unrealscript for use with my HUD.

Anyone know how accessing other classes works in Unreal Script?


Have you taken a look at the Development\Src\UTGame folder? Normally one would advise not looking at source code when learning to do something, however in the circumstance where you are working in an existing engine and trying to make things work in that engine, looking at existing code in my opinion is very valuable (The same constraints they have to make to work with the Unreal engine are probably the same constraints you will have).

Also the '.' operator is used in that manner in Unreal Script.

For instance from UTPlayerController, line 837 (roughly):

reliable server function ServerProcessSpeechRecognition(SpeechRecognizedWord ReplicatedWords[3])
{
	local array<SpeechRecognizedWord> Words;
	local int i;
	local UTGame Game;

	Game = UTGame(WorldInfo.Game);
	if (Game != None)
	{
		for (i = 0; i < 3; i++)
		{
			if (ReplicatedWords[i].WordText != "")
			{
				Words[Words.length] = ReplicatedWords[i];
			}
		}

		Game.ProcessSpeechRecognition(self, Words);
	}
}

Main thing to note is that variables (in this case local variables) must be declared and initialized on two separate lines (as far as I know). Also you need to typecast to the appropriate type containing your methods. such as convertedInstance = MyClass(instanceToConvert) ect. Here we see Game = UTGame(WorldInfo.Game) .



Well I have seen many people typecasting variables from other classes but I'm not exactly sure how it works.

Basically speaking, why can't (using my example)
TestGamePawn.getwaterlevel();

why would this not call the function 'getwaterlevel()' from the TestGamePawn class?

EDIT: Comparing it to C++ shouldn't it work like this:

//Class Declaration
class TestGamePawn
{
 	int charwaterlevel;
Public:
 	
	int getwaterlevel()
{
 	return charwaterlevel;
}

}

//Main
int main()
{
 	int i;
//Calling the class function via member operator.
 	i =TestGamePawn.getwaterlevel();
}

In Topic: Semantic error with a function. I need some troubleshooting help.

07 July 2011 - 07:23 PM

I will bet you money that fixing the missing { changed the behaviour of your program somehow... so what's it do now? ;-)


Actually it didn't change my program at all.

The problem is that the computer is not waiting for user input at the 'getline'.

It does this properly the first time through, however, it doesn't stop (doesn't work properly) after the loop.

And actually, if it will help you, I can attach my current build.

EDIT: Also, if it is helpful: 'charName' is a string class variable [ #include <string> | string charName; ]


EDIT:EDIT: Also, How much money are we talking? Because even if I didn't add the braces and entered 'N' or 'n' the result would be the same. However, I will let you know I am glad you pointed that brace thing out, because when I actually did input 'Y' or 'y' it would have given me problems.

In Topic: Semantic error with a function. I need some troubleshooting help.

07 July 2011 - 07:11 PM

Your problem is that you forgot a { after the else. This means that only the "input not valid" line is attached to the else clause, so userSatisfied is always set false immediately afterwards, and your program loops forever.

This is why indentation is very, very important. Pick a style and stick to it, it'll help you catch these bugs a lot sooner.

[source lang="cpp"]void set_charName(){ using namespace std; bool userSatisfied; char userInput; do { charName = ""; cout << "Name your character. Then press 'Enter/Return'. \n"; getline (cin,charName); system ("cls"); cout << "You have decided to name your character " << charName << ", is this correct?\n (Enter Y/N)"; cin >> userInput; if (userInput == 'Y' || userInput == 'y') userSatisfied = true; else if (userInput == 'N' || userInput == 'n') { userSatisfied = false; system("cls"); } else cout << "Input not valid"; // Oops! userSatisfied = false; system("cls"); } while (userSatisfied == false);}[/source]



I hate to be the bearer of bad news, but this did not solve my problem. However, I am taking your comment about indentation to heart.

In Topic: C++: Problems with classes. Code Included- Need help.

07 July 2011 - 12:56 PM


So is this warning not a bad thing?

"
1>c:\users\brandon\documents\visual studio 2010\projects\theworld\theworld\theworld.cpp(16): warning C4351: new behavior: elements of array 'Character::charstats' will be default initialized
"


Nope. It's just warning you that the same code may have had a different behavior in a prior version of Visual Studio.

EDIT: Also:

What does this error mean?

"1>c:\users\brandon\documents\visual studio 2010\projects\theworld\theworld\theworld.cpp(16): error C2536: 'Character::Character::charstats' : cannot specify explicit initializer for arrays"


Drop the '0' between the parenthesis, and you're good.

Also, if you want a detailed explanation of an error or warning, look it up on MSDN, or Google "msdn Cxxxx". For example, C4351 and C2536





Yea, I've googled Error Codes in the past, but sometimes I don't understand the Microsoft Post. Sometimes it's helpful to get in lay-mans terms. Anyway, thank you very much for your help. And everyone else for theirs. I understand this all a lot better now.

PARTNERS