Variable Speed... HELP PLZ

H

headless_nader

Guest
im fairly new to coding but im familiar with C++
ok... now on to the problem...
Im trying to make it so when you spin the mouse wheel the speed of the RPG changes.. is possible?
i tried this code
Code:
if( MWHEELUP );{
	RPG_SPEED += 10;
}
if( MWHEELDOWN );{
	RPG_SPEED -= 10;
}
but i get syntax errors...

PLZ HELP!
 
The semicolons after the condition in the if clauses

Code:
if( MWHEELUP ) ; {

are wrong :)
 
Angry Lawyer said:
Is RPG_SPEED defined as an integer?

-Angry Lawyer
the line of code is
Code:
#define RPG_SPEED 1500
PrivatePanic said:
The semicolons after the condition in the if clauses


Code:
if( MWHEELUP ) ; {
are wrong
Where should they be?
 
That's defining it as a constant...How familiar are you to C++?

Where exactly are you putting this subroutine, anyways?

-Angry Lawyer
 
Code:
if( MWHEELUP ) {
	RPG_SPEED += 10;
}
if( MWHEELDOWN ) {
	RPG_SPEED -= 10;
}

Look! They're gone *gasp* :)

After the condition should be no ; !
 
Angry Lawyer said:
That's defining it as a constant...How familiar are you to C++?

Where exactly are you putting this subroutine, anyways?

-Angry Lawyer
um... not very...
I know the basic functions and stuff...

i Put it right after the definitions and includes...

i tried this... is this how to set it as an integer?
Code:
int RPG_SPEED=1500;


if( MWHEELUP ){
	RPG_SPEED += 10;
}
if( MWHEELDOWN ){
	RPG_SPEED -= 10;
}
 
heres the error log if you need it...
Compiling...
weapon_rpg.cpp
c:\mym0d\src\dlls\hl2_dll\weapon_rpg.cpp(36) : error C2059: syntax error : 'if'
c:\mym0d\src\dlls\hl2_dll\weapon_rpg.cpp(36) : error C2143: syntax error : missing ';' before '{'
c:\mym0d\src\dlls\hl2_dll\weapon_rpg.cpp(36) : error C2447: '{' : missing function header (old-style formal list?)
c:\mym0d\src\dlls\hl2_dll\weapon_rpg.cpp(39) : error C2059: syntax error : 'if'
c:\mym0d\src\dlls\hl2_dll\weapon_rpg.cpp(39) : error C2143: syntax error : missing ';' before '{'
c:\mym0d\src\dlls\hl2_dll\weapon_rpg.cpp(39) : error C2447: '{' : missing function header (old-style formal list?)

Build log was saved at "file://c:\mym0d\src\dlls\Debug_hl2\BuildLog.htm"
hl - 6 error(s), 0 warning(s)


---------------------- Done ----------------------

Build: 1 succeeded, 1 failed, 0 skipped



Also I tried some code like this:
Code:
int RPG_SPEEDY=150;


if( MWHEELUP ) {
	RPG_SPEEDY += 10;
}
if( MWHEELDOWN ) {
	RPG_SPEEDY -= 10;
}
#define RPG_SPEED RPG_SPEEDY
 
One remark: You shouldn't give variables names in caps (UPPERCASE), that's a little bit bad style; Capitalized names are used typically only for defines (#define BLAH 4711)

It would help if you could post the whole source (cpp file). But don't post it directly here, use a nopaste service like http://rafb.net/paste/index.html
 
Well.

You put your code outside of any class / member function definition, at global scope...


Without sounding too harsh, I'd strongly suggest to you to try something simpler at first, and: Do some c++ tutorials!!!

;)
 
PrivatePanic said:
Well.

You put your code outside of any class / member function definition, at global scope...


Without sounding too harsh, I'd strongly suggest to you to try something simpler at first, and: Do some c++ tutorials!!!

;)

I thought this would be fairly simple... guess not :|
 
With "something simpler" I didn't mean "some simpler HL2 Mod", I meant "something simpler in C++" ;)

A SDK like the HL2 SDK is a huge pile o' C++, you have to be *very* confident in your C++ skills before trying to mess with the HL2 SDK or similar complex Engines.
 
Code:
if( MWHEELUP )
RPG_SPEED += 10;

if( MWHEELDOWN )
RPG_SPEED -= 10;

no need for ; or {}

Edit - the {} are only used for lines of code longer than 1 line. For instance

Code:
if(MWHEELDOWN == true) {
int rpg_speed = 100;
rpg_speed -= 10;
MWHEELDOWN = false
}

the {} are used because there's more than one line of code under the if statement.

edit - and btw, if you didn't know that, I dunno what you're doing in the hl2sdk. Try modding doom legacy or something.
 
Back
Top