MODSonline
  Welcome Guest to MODSonline Home | Forums | Register | Login
Main-Menu
Home
Login
Register
Add Download
Add News
Add Tutorial *
Forums

Advertise
Affiliate Store US *
Affiliate Store UK *
Affiliate Store CA *
Angry Letter Generator
Avatar Upload
Calendar of Games
Contact
Downloads
FAQs
Forums
Member List
Member Projects
News
News Grabber *
Policy
Polls
Private Messages
Reviews
Screenshot Gallery
Search
Servers - Game
Store - Shirts *
Subscribe
Topics
Tutorials
Weblinks
Wiki *
Tutorials
CoD Mapping
CoDUO Mapping
CoD2 Mapping
CoD4 Mapping
CoDWW Mapping
CoD FAQs
HL2 Mapping
HL2 FAQs
SOF1 Mapping
Crysis Mapping
Q4 Mapping
Doom 3 Mapping
Doom 3 FAQs
UT2K3 Mapping
SOF2 Mapping
SOF2 FAQs

Lightray Modeling
General Modeling
General Modding
Adobe Photoshop
Common Mapping Errors

Readme.txt Generator
Members-Online
SparkyMcSp... [Today]
[-X-]Fried... [Today]
starkk [Today]
deadelvis [Forum]
MetalMilit... [Forum]
jace [Forum]
mrsilvers [Forum]
4sakin [Forum]
Bull [Downl]
*UWS*KILL_... [Forum]
syfer016 [Proje]
JerryAtricks [Forum]
FataLOneDay [Today]
Welshy [Today]

14 Members and 12 Guests
Chat MODSonline
0 People Now Chatting
MODSOnline TeamSpeak

download TeamSpeak

In-The-News
Monday, Dec. 1st
A message from foyleman
Sunday, Nov. 30th
MODSonair 156 Live
Friday, Nov. 28th
MODSonair Episode 155
Wednesday, Nov. 26th
MODSonair Forum Buttons
Monday, Nov. 24th
Holiday Gift Guide 2008 - PC
Latest Poll
Single or Multiplayer maps for World at War?
Single-Player 29.21%
Multiplayer 62.92%
WHAT!? The tools are out? 7.87%
Read More...
10 comments

Newsletter
Name:
Email:
Newsletter Archives
Your Membership
User Name:
Password:
Register.
In The Forums
Minimap Weirdness...
CoD 4 Level Desi.. Posts: (3) Views: (29) by JerryAtricks
ERROR: CodeCallback_StartGameType[]
CoD 4 Level Desi.. Posts: (10) Views: (59) by JerryAtricks
Mirror's Edge PC Release Date Announced
News Around the .. Posts: (2) Views: (2) by supersword
EFFECTS ERROR
CoD 4 Level Desi.. Posts: (4) Views: (57) by JerryAtricks
Google 468 Banner Quake 4 Mods for Dummies
CoDWW Download
Forums
MODSonline.com Forums

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, rEdrUmMDK, Foxhound, Wyatt_Earp, Rasta, StrYdeR, The_Caretaker, Cypher2004, batistablr, Welshy
Latest Posts
Subscribed Posts
Search
Restricted Access Restricted Access subscribe
Author Topic: help with defining variable
cybershot
General Member
Since: Dec 28, 2005
Posts: 917
Last: May 18, 2008
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Thursday, Nov. 15, 2007 02:51 am
i have been messing with this script and trying to get it to recognize names. i found a line that says if(self.player ==... so i thought i could do if(self.player == cybershot) that would work, but i get undefined variable. where is the variable..the main thing i am trying to do is learn how to script so this post will server many functions. also i am not sure if i need the return true at the end of the if statement and i don't know what the return true would do anyway so if you can explain that or what even any return means that would be great. thanks.

Code:
main()
{


trigs = getentarray("shoot_trig", "targetname");
for(i=0;i


edited on Nov. 15, 2007 02:51 am by cybershot
(VM)Monkey
General Member
Since: Jul 31, 2006
Posts: 113
Last: Mar 24, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Thursday, Nov. 15, 2007 03:45 am
The unitiliazed variable is cybershot. What you're trying to do is compare it to a string, in which case it should be

if (player.name == "cybershot")

As far as the return true; part, that depends on what you're trying to do.

for any if statement, if the condition is true (player.name == "cybershot), then it performs the action after it, or the group of actions if they're surrounded by { }.

In this case, if the player.name does equal "cybershot", then, unless i'm mistaken, the monitor_trigger function is exited, returning a value of true. Nothing further is done, and that function stops running.

I think what you're trying to do is something more like this:

while(1)
{
self waittill("trigger", player);
if (player.name != "cybershot")
player suicide();
}

The big thing is that you need to have the self waittill("trigger", player); before the if statement. The first reason is that the waittill declares the player variable (another possible undeclared variable), and generally, you want the trigger to be triggered before you do any checks.

With this code, once the trigger is activated, it checks the player's name, and if it is not "cybershot", then the player dies.
cybershot
General Member
Since: Dec 28, 2005
Posts: 917
Last: May 18, 2008
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Thursday, Nov. 15, 2007 10:17 am
that is what i am trying to do Monkey. i forgot about the does not part != that would make it easier, however, i still get the unititialized variable on my name.
(VM)Monkey
General Member
Since: Jul 31, 2006
Posts: 113
Last: Mar 24, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Thursday, Nov. 15, 2007 11:09 am
If you type /developer 1 in the console before you run your map, and then bring up the full console (shift+~), where it tells you that you have an uninitialized variable, it should show you the line it's from and put an asterisk underneath the variable that it uninitialized.
(VM)Monkey
General Member
Since: Jul 31, 2006
Posts: 113
Last: Mar 24, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Thursday, Nov. 15, 2007 11:20 am
I just tried this and it worked:


Code:
main()
{

trigs = getentarray("shoot_trig", "targetname");
for(i=0;i


Not sure why it isn't working for you. [ohwell]

edited on Nov. 15, 2007 11:22 am by (VM)Monkey
cybershot
General Member
Since: Dec 28, 2005
Posts: 917
Last: May 18, 2008
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Thursday, Nov. 15, 2007 07:56 pm
it didn't work for me because i was missing the quotes around my name if(self.player != "cybershot"); i had if(self.player != cybershot) i also had a space between the if (. now it wouldn't work with the color codes for some reason. i had to take out the color to get it to work for me. but it's working now. thanks for you input on this.. one other question if i may? i thought all if statements needed to have their own curly braces "{" why doesn't the if statement in this code need a curly brace? so i thought it would have looked like this

if(player.name != "cybershot);
{
player suicide();
}
(VM)Monkey
General Member
Since: Jul 31, 2006
Posts: 113
Last: Mar 24, 2008
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Saturday, Nov. 17, 2007 01:26 am
Sorry it took so long to respond.

The best way I can explain it is to consider the brackets ({ and }) as a sort of box. Anything between { and } is inside that box.

The if, else, while, for, etc statements only run the next command. Think of them as a person who you can only hand one thing to at a time.

For example, if you had

for(x=0;x<5;x++)
iprintlnbold(x);
iprintlnbold("hi");

it would print
0
1
2
3
4
hi

Using the analogy of the person who can only be handed one item at a time, if you take a box, and fill it full of stuff, you can hand him the full box, and he'll take it, because it's only "one" item. The same is with the brackets. If you put a bunch of statements in the brackets, you can tell the function to run this "one" command.

For example,

for (x=0;x<5;x++)
{
iprintlnbold(x);
iprintlnbold("hi");
}

it would print

0
hi
1
hi
2
hi

... etc

Anyway, it's not necessary to use brackets if you're just doing one command. It does help to make it easier to read sometimes though, unless you religiously indent your code.

Hopefully that didn't confuse you more. [crazy]



edited on Nov. 17, 2007 01:30 am by (VM)Monkey
cybershot
General Member
Since: Dec 28, 2005
Posts: 917
Last: May 18, 2008
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Saturday, Nov. 17, 2007 08:04 pm
thanks for responding. i think i get it.
Restricted Access Restricted Access subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting
All logos and trademarks and information in this site are property of MODSonline LLC © 2008.
The comments are property of their posters.
RSS news feeds for MODSonline can be found News.php.
MODSonline Subscriptions
Partners
modbase.be
CODAddicts - Call of Duty News & Downloads
Call of Duty Headquarters
The Firing Box
Battle for Europe COD2
XoXide
Frag Universe
Ask About
Advertising
Friends
Great Gamer
ModTheater
Volcano
Ask About
Advertising
Link to Us
MODSonair
View in iTunes
Please help us to raise in the ranks of podcasting and subscribe to our itunes feed using the link above.
MODSonair Releases
MODSonair Episode 155
MODSonair Episode 154
MODSonair Episode 153
MODSonair Episode 152
MODSonair Episode 151
Next Show
The next MODSonair show will air LIVE on:
12/07/2008 12:00 EST

Time remaining:
Copyright © 2008 MODSonline
Tresware Content Management System Copyright © 2008 Tresware
Website Designed and Hosted   Tresware