Wierd problem
#1

I have created a function that called LoadGas
I have located it at OnGameModeInit like that:

Код:
LoadGas();
The problem is that OnGameModeInit function just ignores what comes after that line.

This is the function:

Код:
stock LoadGas()
{
	new s = sizeof(FuelTanks);
	for(new i=0;0<s;i++)
	{
	    CreateDynamicObject(3465, FuelTanks[i][0], FuelTanks[i][1], FuelTanks[i][2], 0.00000, 0.00000, FuelTanks[i][3]);
	    new gas[50];
	    format(gas,50,"Gas Tank\n/v fill yo use\n%d$ per liter", gasprice);
	    Create3DTextLabel(gas, COLOR_WHITE, FuelTanks[i][0], FuelTanks[i][1], FuelTanks[i][2], 32.0, 0, 0);
	}
	return 1;
}
There are no warnings/errors.
Reply
#2

Put it in the last line then :P

I think there should be a forward or something, I don't think LoadGas is a function here, it's a stock, a funtion I think is Like
pawn Код:
forward LoadGas();
public LoadGas()
{
    new s = sizeof(FuelTanks);
    for(new i=0;0<s;i++)
    {
        CreateDynamicObject(3465, FuelTanks[i][0], FuelTanks[i][1], FuelTanks[i][2], 0.00000, 0.00000, FuelTanks[i][3]);
        new gas[50];
        format(gas,50,"Gas Tank\n/v fill yo use\n%d$ per liter", gasprice);
        Create3DTextLabel(gas, COLOR_WHITE, FuelTanks[i][0], FuelTanks[i][1], FuelTanks[i][2], 32.0, 0, 0);
    }
    return 1;
}
Just try this, I'm maybe wrong, I don't know
Reply
#3

I used it as a public before it didn't solve it

And I want a better solution than put it in the last line :P
Reply
#4

First of all, whats the size of the array 'Fuel Tanks'?

And also, more efficiently, use this: (doesn't mean it's fixed)
pawn Код:
forward LoadGas();
public LoadGas()
{
    new gas[50];
    for(new i = 0, s = sizeof(FuelTanks); i < s; i++)
    {
        CreateDynamicObject(3465, FuelTanks[i][0], FuelTanks[i][1], FuelTanks[i][2], 0.00000, 0.00000, FuelTanks[i][3]);
        format(gas,50,"Gas Tank\n/v fill yo use\n%d$ per liter", gasprice);
        Create3DTextLabel(gas, COLOR_WHITE, FuelTanks[i][0], FuelTanks[i][1], FuelTanks[i][2], 32.0, 0, 0);
    }
    return true;
}
EDIT: You were doing "0 < s" and making the 'i' variable increment.
So thats why it wouldn't do nothing after that function.
It was doing an infinite loop.

EDIT2: Shoot! MP2 beat me at it! Screw you. :P
Reply
#5

Look at this line:

for(new i=0;0<s;i++)

For a start, if you spaced it out, it's easier to read:

for(new i=0; 0<s; i++)

Then you may notice the second expression is wrong. It's causing an infinite loop, because 's' will always be 1+, so 'while 0 is less than 1/2/3/etc.' is always going to be true. It's meant to be i, not 0.
Reply
#6

Quote:
Originally Posted by MP2
Посмотреть сообщение
Look at this line:

for(new i=0;0<s;i++)

For a start, if you spaced it out, it's easier to read:

for(new i=0; 0<s; i++)

Then you may notice the second expression is wrong. It's causing an infinite loop, because 's' will always be 1+, so 'while 0 is less than 1/2/3/etc.' is always going to be true. It's meant to be i, not 0.
Yeah really stupid of me, just noticed it lol.
Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)