4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
syntax error
#295552
10/26/09 01:56
10/26/09 01:56
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
Could someone please tell me what is wrong with this code.
var place = 0;
//Function for creating pickups
function pickups_places()
{
place = int(random(6));
if (place == 1)
{ent_create("pass.mdl",vector(-192,-192,0),NULL);}
if (place == 2)
{ent_create("pass.mdl",vector(-160,-192,0),NULL);}
if (place == 3)
{ent_create("pass.mdl",vector(-128,-192,0),NULL);}
if (place == 4)
{ent_create("pass.mdl",vector(-96,-192,0),NULL);}
if (place == 5)
{ent_create("pass.mdl",vector(-64,-192,0),NULL);}
}
pickups_places(); //this is in the main function
|
|
|
Re: syntax error
[Re: JGGamer]
#295555
10/26/09 03:26
10/26/09 03:26
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
place = integer(random(6));
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: syntax error
[Re: EvilSOB]
#295703
10/27/09 00:13
10/27/09 00:13
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
Thanks. I would never have found that out. I was using the manual and I never came across this. Thanks again. editSorry to be a bother. I am not gettin any results from the code. When I just do
ent_create("pass.mdl",vector(-192,-192,0),NULL);
I get results. The 'pass' model appears, but when I use the code above, the model doesn't appear. Is everything ok with my code or have I done something wrong?
Last edited by JGGamer; 10/27/09 00:26.
|
|
|
Re: syntax error
[Re: JGGamer]
#295707
10/27/09 01:02
10/27/09 01:02
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
sometimes comparing a var with a real numberm as you are doing doesnt work. Its buried deep in the manual somewhere, from memory, it goes something like ...sometimes a var will not contain the expected integer, but contain a near value, where one is expecting a 1.000, you will in fact get a 1.000001 which causes the if to fail... or something to that effect. try this instead. (untested)
//Function for creating pickups
function pickups_places()
{
place = random(6);
if (integer(place) == 1)
{ent_create("pass.mdl",vector(-192,-192,0),NULL);}
if (integer(place) == 2)
{ent_create("pass.mdl",vector(-160,-192,0),NULL);}
if (integer(place) == 3)
{ent_create("pass.mdl",vector(-128,-192,0),NULL);}
if (integer(place) == 4)
{ent_create("pass.mdl",vector(-96,-192,0),NULL);}
if (integer(place) == 5)
{ent_create("pass.mdl",vector(-64,-192,0),NULL);}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: syntax error
[Re: JGGamer]
#295712
10/27/09 03:01
10/27/09 03:01
|
Joined: Apr 2006
Posts: 624 DEEP 13
badapple
User
|
User
Joined: Apr 2006
Posts: 624
DEEP 13
|
maybe try it like this
if((place >= 0)&&(place < 2)) {ent_create("pass.mdl",vector(-192,-192,0),NULL);} if((place >= 2)&&(place < 3)) {ent_create("pass.mdl",vector(-160,-192,0),NULL);} if((place >= 3)&&(place < 4)) {ent_create("pass.mdl",vector(-128,-192,0),NULL);} if((place >= 4)&&(place < 5)) {ent_create("pass.mdl",vector(-96,-192,0),NULL);} if(place >= 5) {ent_create("pass.mdl",vector(-64,-192,0),NULL);}
|
|
|
Re: syntax error
[Re: badapple]
#295716
10/27/09 03:52
10/27/09 03:52
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
I also tried that and it didn't work either. However, I made a little progress. I debugged the variable place, and realized that it never moved from zero, so I tried using a while loop and the model appeared but in all 5 places. I then tried this:
var place;
var trigger_num = 0;
var trigger_mod;
if (trigger_num == 0)
{
trigger_mod = ent_create("pass.mdl",vector(0,0,0),pickups_places);
trigger_num = 1;
}
//Function for creating pickups
function pickups_places()
{
while (place == 0)
{
place = integer(random(6));
if (place == 1)
{ent_create("pass.mdl",vector(-192,192,0),NULL);}
if (place == 2)
{ent_create("pass.mdl",vector(-160,192,0),NULL);}
if (place == 3)
{ent_create("pass.mdl",vector(-128,192,0),NULL);}
if (place == 4)
{ent_create("pass.mdl",vector(-96,192,0),NULL);}
if (place == 5)
{ent_create("pass.mdl",vector(-64,192,0),NULL);}
wait(1);
}
}
This time only one model appears, but it always appear in the same position. The variable 'place' is always 3. Any ideas on this?
|
|
|
Re: syntax error
[Re: JGGamer]
#295720
10/27/09 04:24
10/27/09 04:24
|
Joined: Nov 2008
Posts: 109
JGGamer
OP
Member
|
OP
Member
Joined: Nov 2008
Posts: 109
|
I don't get it. I removed the interger and used:
//Function for creating pickups
function pickups_places()
{
while (place == 0)
{
place = random(6);
wait(1);
}
if (place > 0 && place < 2)
{ent_create("pass.mdl",vector(-192,192,0),NULL);}
else if (place >= 2 && place < 3)
{ent_create("pass.mdl",vector(-160,192,0),NULL);}
else if (place >= 3 && place < 4)
{ent_create("pass.mdl",vector(-128,192,0),NULL);}
else if (place >= 4 && place < 5)
{ent_create("pass.mdl",vector(-96,192,0),NULL);}
else if (place >= 5 && place < 6)
{ent_create("pass.mdl",vector(-64,192,0),NULL);}
}
and now variable place is 0.995 all the time. Could someone who knows whats going on here please help me with this. It's sending me crazy. Thanks for your help guys.
|
|
|
Re: syntax error
[Re: JGGamer]
#295733
10/27/09 07:24
10/27/09 07:24
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Try this one, and let us know IF it fixes the problem, if it does then I'll explain it. Im not good with c-script so it may need adjusting to be c-script friendly.
//Function for creating pickups
function pickups_places()
{
random_seed(0);
var place = integer(random(5)+1);
if(place==1) {ent_create("pass.mdl",vector(-192,192,0),NULL);}
if(place==2) {ent_create("pass.mdl",vector(-160,192,0),NULL);}
if(place==3) {ent_create("pass.mdl",vector(-128,192,0),NULL);}
if(place==4) {ent_create("pass.mdl",vector(-96,192,0),NULL);}
if(place==5) {ent_create("pass.mdl",vector(-64,192,0),NULL);}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|