Log in

View Full Version : failure passing var to spawn2 or PEBCAK?


Davood
11-08-2012, 01:13 AM
PLEASE let the answer be PEBCAK.

Ok so I have a script that spawn an npc based on a variable for the spawn ID

This causes a zone.exe crash everytime

When tested, @row[0] = 2700972
that value is the npc_id for that particular case, that I want to spawn..

Without posting all of my plugins and such... lets pretend that

(It does some work and produces a @ array, after searching the DB for some parameters using a db plugin)

This crashes zone.exe
my $var_to_test = @row[0]
quest::spawn2($var_to_test,0,0,$x,$y,$z,$h);

This also crashes zone.exe
quest::spawn2(@row[0],0,0,$x,$y,$z,$h);

HOWEVER
this does NOT crash zone.exe, and it works and spawns the npc - but is useless to me because i am hardcoding it in that case.
my $var_to_test = 2700972;
quest::spawn2($var_to_test,0,0,$x,$y,$z,$h);

WTF is perl doing when I transfer it from @ to $??????? I did some searches and couldnt figure it out

i tried
my ($var_to_test) = @row;
which supposedly takes the first value from row, but that didn't work - even though another variable test showed the right number again.

i also tried casting $var_to_test with int($var_to_test)

I saw something about "blessing" a variable.. is this something i need to do? (i couldn't understand what blessing meant)

c0ncrete
11-08-2012, 06:32 AM
PEBKAC :)

to access an element via index, you want to use $array_name[$index] not @array_name[$index]

don't worry about bless() unless you're writing custom classes.

also note that if you are declaring a variable with 'my' and assigning a value to it inside of a loop, it won't be available outside of that loop.

Davood
11-08-2012, 08:27 PM
its still failing with $

i tried passing it to another $ and i tried putting it directly into spawn2

it crashes zone either way.... i even tried closing the db connection - no dice.

lerxst2112
11-08-2012, 08:45 PM
Well, I'd advise using the debugger to see what gets passed into the c++ side and also where it crashes.

Davood
11-08-2012, 09:22 PM
ok lerxst2112,.. ill check into that if i can't find something useful in the logs

i think it might be somethign to do with teh mysql server actually.. sometimes it doesnt crash but a #dbspawn 2700947 or whatever will crash teh zone

i'll do some more research.. i may be doing something bad to the db :P

Davood
11-09-2012, 12:38 AM
nevermind about this, it was a poor method of delivery.. i have devised an even less efficient method well see how it plays out ;o