Is there any safer way to do this?
#1

Hello, hope you're having a great day,
so is there a better way to do this,
PHP Code:
foreach(new EVM){
    
format(ghsizeof(gh), "iterator: %d"i);
    
SendClientMessage(playeridEVMCOLOR_REDgh);
    
Iter_Remove(EVMi);

ofc, it doesn't not work,
Debugging
Code:
Code 1:
foreach(new I : EVM)
     print(i);

Result:
Iterator: 0
Iterator: 1
Iterator: 2
Iterator: 3
Iterator: 4
Iterator: 5


Code 2:
foreach(new I : EVM){
     print(i);
     Iter_Remove(i);
}

Result:

sometimes it shows random numbers
Iterator: 26(The first iterator appears here)
Iterator: 0(always shows 0)
Iterator -33161(always shows this number)


some other times the server just crashes
Reply
#2

Might showing us what EVM actually is?
Reply
#3

Iter_SafeRemove inside foreach loops.
Reply
#4

Quote:
Originally Posted by Logic_
View Post
Might showing us what EVM actually is?
Iterator:EVM<MAX_EVMs> with MAX_EVMs being 150
Reply
#5

Quote:
Originally Posted by Eoussama
View Post
Iterator:EVM<MAX_EVMs> with MAX_EVMs being 150
Have you tried this?
Reply
#6

Quote:
Originally Posted by Paulice
View Post
Have you tried this?
yes, and this is the result

Code:
foreach(new i : EVM){
    printf("Iterator: %d", i);
    new cur = evmID;
    Iter_SafeRemove(EVM, cur, evmID);
}

Iterator: 7
Iterator: 0
Iterator: -39800
this problem only occurs if I do this
PHP Code:
foreach(new EVM)
        
DeleteEVM(i);
DeleteEVM(evmID){
    
EVMInfo[evmID][e_evmName][0] = EOS;
    
EVMInfo[evmID][e_evmPosX] = 0;
    
EVMInfo[evmID][e_evmPosY] = 0;
    
EVMInfo[evmID][e_evmPosZ] = 0;
    
EVMInfo[evmID][e_evmRotX] = 0;
    
EVMInfo[evmID][e_evmRotY] = 0;
    
EVMInfo[evmID][e_evmRotZ] = 0;
    
EVMInfo[evmID][e_evmIsBlocked] = true;
    
DestroyDynamicObject(EVMInfo[evmID][e_evmObj]);
    
DestroyDynamic3DTextLabel(EVMInfo[evmID][e_evmLabel]);
    new 
cur evmID;
    
Iter_SafeRemove(EVMcurevmID);

but it works fine if I do this

PHP Code:
foreach(new EVM){
        
DeleteEVM(i);
        new 
cur i;
    
Iter_SafeRemove(EVMcuri);
}
DeleteEVM(evmID){
    
EVMInfo[evmID][e_evmName][0] = EOS;
    
EVMInfo[evmID][e_evmPosX] = 0;
    
EVMInfo[evmID][e_evmPosY] = 0;
    
EVMInfo[evmID][e_evmPosZ] = 0;
    
EVMInfo[evmID][e_evmRotX] = 0;
    
EVMInfo[evmID][e_evmRotY] = 0;
    
EVMInfo[evmID][e_evmRotZ] = 0;
    
EVMInfo[evmID][e_evmIsBlocked] = true;
    
DestroyDynamicObject(EVMInfo[evmID][e_evmObj]);
    
DestroyDynamic3DTextLabel(EVMInfo[evmID][e_evmLabel]);

so there is no way I can use Iter_SafeRemove inside a separae function?
Reply
#7

Since you're "deleting" all EVMs, simply use Iter_Clear(EVM); after the foreach loop (removing the need of Iter_Remove/Iter_SafeRemove - Iter_Remove cannot be used within a loop that uses the self iterator btw).
Reply
#8

Quote:
Originally Posted by Paulice
View Post
Since you're "deleting" all EVMs, simply use Iter_Clear(EVM); after the foreach loop (removing the need of Iter_Remove/Iter_SafeRemove - Iter_Remove cannot be used within a loop that uses the self iterator btw).
thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)