strins
#1

I'm thinking its because it's so damn late, but I need some help with this.

Currently, what I have is a phone system that I'm trying to get to work.

Here are the variables:
pawn Код:
new
            cellDialedNumber [ MAX_PLAYERS ] [ 30 ],
            cellDialStage [ MAX_PLAYERS ] = 9;
Now, the original string is "000000000", I'm trying to insert the number they hit next in line. Like say they hit 1;

"000000000" would turn into "000000001", and if they hit 1 again (or any other number for that matter), it would turn into "000000011", and so on. How would I go about doing this?

I've attempted, but I'm figuring it's too late because I can't seem to get it working.

pawn Код:
if(clickedid == DialPadOne )
        {
            new s[128]; // Testing string.
            strdel( cellDialedNumber [ playerid ], 9, 10 );
            strins( cellDialedNumber [ playerid ], "1", cellDialStage [ playerid ] );
            format(s, 128, "%s", cellDialedNumber [ playerid ] ); // Testing.
            SendClientMessage( playerid, -1, s); // Testing.
            SendClientMessage( playerid, -1, "One" ); // Testing.
           
            cellDialStage [ playerid ] -= 1;
        }
What am I doing wrong?
Reply
#2

You could probably do

pawn Код:
new last_mult[MAX_PLAYERS]=0;

//in the func
new mult;

//Here we check the last multiplier, if it's not, we multiply the last mult by 10
//That way we end up with...mult=1, mult=10, mult=100, mult=1000, mult=10000, until we reach the end of our stages
if(!last_mult[playerid]) mult=1;
else mult=last_mult[playerid]*10;

//Here we add the number they typed multiplied by our multiplier to the current number
cellDialedNumber[playerid]+=change_this_to_the_number_they_typed*mult;

//Set the last multiplier to the current multiplier
last_mult[playerid] = mult;


cellDialStage[playerid]++;
if(cellDialStage[playerid] == 9) Do_The_Call_Thing_Here();
/*
Basically we'll end up with....

Stage 1 = 5 (*1)
Stage 2 = 7 (*10)
Stage 3 = 8 (*100)
Stage 4 = 1 (*1000)
Stage 5 = 4 (*10000)
Stage 6 = 3 (*100000)
so on

Eeach one will take the next digit over
*/
So basically, we instead of...subtracting the stages, we add them up to 9

Also, make sure you reset the last_mult to 0 when they did their call or whatever - and reset the dialed number
Reply
#3

EDIT: Alright, I've given it a shot, and I have recieved an error.

pawn Код:
if(clickedid == DialPadOne )
        {
            new
                mult,
                s[128];
           
            if( !cellLastMultiplier[playerid] ) mult = 1;
            else mult= cellLastMultiplier[playerid] * 10;
           
            cellDialedNumber [ playerid ] += 1 * mult;
            cellLastMultiplier [ playerid ] = mult;
            cellDialStage [ playerid ] ++;
           
            if(cellDialStage[playerid] == 9) {
            format(s, 128, "%s", cellDialedNumber [ playerid ] );
            SendClientMessage( playerid, -1, s);
            }
            SendClientMessage( playerid, -1, "One" );
        }
pawn Код:
cellDialedNumber [ playerid ] += 1 * mult;
is giving me error 023: array assignment must be simple assignment.
Reply
#4

What if you put bracets around the mutliplication? [..] += (1*mult);
Reply
#5

I'm an idiot. I had forgot I originally created cellDialedNumber as a string. It's working! Thanks so much!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)