Page 1 of 1
rand() expects parameter 1 to be long ???
Posted: Wed Oct 06, 2010 11:54 am
by tomtefan
iam a noob, so i cant see whats wrong yet.
rand() expects parameter 1 to be long, string given in c:\blablabla
thats the warning i get on this line..
$creaturetext1 = $creatureinfo3['text1'];
$creaturetext2 = $creatureinfo3['text2'];
$attack = rand($creatureinfo3['text1'],$creatureinfo3['text2']);
CODE LINE:
echo "The " . $creature . " Rush towards you and " . $attack . " and hits " . $location ." .<br>";
it cant be to long in DB. cuz i have it Varchar 77 and iam only using around 20-30 letters for a hit text.
What the line SHOULD do is:
The bear........Rush towards you and....Attacks with its giant razor sharp claws,....and hits.....your Head.
$creature............................................(hittext1 or hittext2)...................................($location)
iam trying to flip around stuff, but i cant see whats wrong still.
Most likely something easy.
any help whould be nice

Re: rand() expects parameter 1 to be long ???
Posted: Wed Oct 06, 2010 2:02 pm
by hallsofvallhalla
because you rand() is only used for numbers, I am assuming craturetext is a characters and not numbers
Instead have the query select one of the texts by RAND.
Re: rand() expects parameter 1 to be long ???
Posted: Wed Oct 06, 2010 2:22 pm
by tomtefan
hmm, ye, figured it should be something like that.
but thats good also, cuz then i can put in more random hittexts
whould get boring to only have 2 random texts per monster.
think i will try and put in 5+ different ones atleast to get it more alive.
damn, wish i was more heavy on php coding. i just got more ideas about hittexts. damnit.
anyways ty for answer.

Re: rand() expects parameter 1 to be long ???
Posted: Wed Oct 06, 2010 5:25 pm
by hallsofvallhalla
i used it in quests of crocania
this is if we get a random encounter and no buildings are there
Code: Select all
$randevent = rand(0,100);
if ($randevent < 14 && $mapinfo3['stature'] == 'none')
{
$event = 1;
$eventinfo="SELECT * from events where level<='$playerinfo3[level]' AND map = '$map' order by rand() limit 1";
$eventinfo2=mysql_query($eventinfo) or die("Could not get event");
$eventinfo3=mysql_fetch_array($eventinfo2);
}
i basically have a table in the DB called events, it has level of event and text of the event...along with other non important things(loot, creature id, ect..)
this way you just print the random event
Re: rand() expects parameter 1 to be long ???
Posted: Thu Oct 07, 2010 3:32 pm
by tomtefan
i went along and did this with my random attack texts.
$attack = $randattack;
$randattack = rand(1,5);
if ($randattack <= 2)
{$attack = $creatureinfo3['text1'];}
elseif ($randattack <= 3)
{$attack = $creatureinfo3['text2'];}
elseif ($randattack <= 4)
{$attack = $creatureinfo3['text3'];}
elseif ($randattack <= 5)
{$attack = $creatureinfo3['text4'];}
echo "The " . $creature . " Rush towards you and " . $attack . " and hit your " . $location ." .<br>";
How ever i get a: Notice: Undefined variable: randattack
The random text works, but the warning is annoying.
how can i fix that ?
Re: rand() expects parameter 1 to be long ???
Posted: Thu Oct 07, 2010 3:40 pm
by Chris
if ($randattack <= 2)
elseif ($randattack <= 3)
Erm.. that means it's going to do something really weird here.. because.. basically that's saying:
if randattack is greater or equal to 2 do something, else if randattack is greater or equal to 3 do something..
So say randattack is 4.. well that's both grater than 2 and 3.. so both instances are true.
The warning you're getting is because you're calling a variable that doesn't exist.
Here's how it works:
This should show a warning because $variable doesn't exist.
You would need to first check if it does exist:
Code: Select all
<?php
if( empty($variable) )
{
echo 'Nope not there.. sorry';
}
else
{
echo $variable;
}
Re: rand() expects parameter 1 to be long ???
Posted: Thu Oct 07, 2010 3:43 pm
by tomtefan
ok.. ty. will check it when i get back home.
yey.. fixed it by: instead of < or > just using ==
$randattack = rand(1,4);
if ($randattack == 1)
{$attack = $creatureinfo3['text1'];}
elseif ($randattack == 2)
{$attack = $creatureinfo3['text2'];}