Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    373

    Default why SetTimer cannot be used with a function that takes parameters?

    If it could use a function that takes arguments then that could simplify a lot my code!!!
    Can this be taken as a request for future functionality please?
    till now to overcome this im using member variables but sometimes you need more and more this variables to get the things going and the level of entropy begins to get bigger and bigger and that's always dangerous...
    do you want to learn UDK and you are a newbie?
    - first learn some basics about level edition
    - then do make Hourences Basic Game Tut. to work (dont go further till you make it work)
    - and only then learn the Mougli's lessons
    - official UDK info

  2. #2
    Palace Guard

    Join Date
    Jul 2006
    Location
    WorldInfo_61
    Posts
    3,170

    Default

    You could use a tick function (cant believe Im suggesting it) but you can use locals in there and pass to the function you want to call each tick then disable tick when its not required.

    I think itd be difficult to implement timers taking parameters since the function is passed by name so theres no way to tell if the function in question has the required amount of parameters. Its not like some other languages where you can define the same function with numerous different parameter sets. Best case would be a delegate and even then you could only pass certain types already defined, trying to use a string would just be messy as hell.

  3. #3
    Prisoner 849
    Join Date
    Apr 2010
    Posts
    891

    Default

    Yeah i also would like such a feature, btw for what exactly is the last "Obj" parameter in SetTimer()? Just the actor that will run the timer?

    @MonsOlympus: Why not allow the old c style void* logic? So just define one optional allowed "Object" parameter for all TimerFunctions, that get passed to the timer.
    Than the Timer needs to cast the Obj to whatever type it needs. If u just want hand over strings just create a struct or wrapper obj u can put the string into. Thats how many programs in c/c++ handle "undefined" function parameters. I know its not "perfectly" OOP, but hey i have seen some crazy code in UDK already

    bye Andy
    Last edited by AndyPandy; 03-04-2011 at 11:33 AM.

  4. #4

    Default

    OMG, "void*" is the most un-OOP-ish concept ever. Don't even thing about something like that.
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
    <TNSe> nono
    <TNSe> its always funny to find code a week later you dont even remember writing
    <Pfhoenix> what's worse is when you have a Star Wars moment
    <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"

  5. #5
    Prisoner 849
    Join Date
    Apr 2010
    Posts
    891

    Default

    Quote Originally Posted by Wormbo View Post
    OMG, "void*" is the most un-OOP-ish concept ever. Don't even thing about something like that.
    Actually it is not directly related to OOP in general, it more relates to the question if a OOP language has pointer support or not. Most languages that support pointers also support void pointers.

    But what i suggested in script is actually not a real void*, but more like a object reference, but this wont allow structs to be handed over.

    But since we are in a interpreted language, UT can securely support "pseudo" void pointers. Which just means a undefined reference to a Object or data structure u can hand over. This could still be a secure operation, since its not hard compiled and the cast can be checked and validated at runtime like a dynamic_cast in c++.

  6. #6
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,828

    Default

    I think if you're in need of running a lot of timers that takes parameters, you may be doing something incorrectly, considering that that's not supported, it would probably be better to build it in a way that you don't have to deal with that, rather than hoping for it to happen someday
    Trendy Entertainment
    http://www.trendyent.com/ http://www.dungeondefenders.com/
    - Please don't send me private messages asking programming questions, those would be better asked on the Programming forum here. Thanks
    - Thoughts and opinions expressed by me are not meant to express the thoughts and opinions of Trendy Entertainment or anyone else related to Trendy.

  7. #7

    Default

    The dynamic_cast in C++ corresponds to UnrealScript's standard typecasting behavior. Your most generic pointer would be of type Object. Right, you can't pass basic types or structs/arrays that way. Then again, those are never pointers anyway in UnrealScript and it's a good thing.
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
    <TNSe> nono
    <TNSe> its always funny to find code a week later you dont even remember writing
    <Pfhoenix> what's worse is when you have a Star Wars moment
    <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"

  8. #8
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    373

    Default

    Finally I ended following MonsOlympus suggestion (I had thought that too but I didnt like it...), creating various versions of the same function using each different member variables..
    take a look and laugh!! (remember that my game is a shoot'em up top view vertical scrolling, so I need to be spawning enemies dynamically), with SetTimer supporting parameters I only would need only 25 lines of code to do the same.
    Code:
    /** SImplifica el "spawneado" dinámico de enemigos permitiendo la "simultaneidad". Talvez poco elegantemente pero simplifica bastante el scripting en SamGameInfo */
    class EnemySpawnMgr extends actor; 
    
    var name AttackType_A, EnemyType_A;
    var name AttackType_B, EnemyType_B;
    
    /** Esta función simpifica el "espawneado" de enemigos, su temporización y "despeje" */
    /** SQUAD A*/ 
    function SetSquad_A(name EnemyType, name AttackType, float Periodo, float Lifetime)  {
    		EnemyType_A = GetSpawnFunctionName(EnemyType, "A");
    		AttackType_A = AttackType;
    		SetTimer(Periodo, true, EnemyType_A); // espawneado de enemigos cada Periodo segundos
    		SetTimer(LifeTime, false, 'ClearSquad_A'); // eliminación de timer anterior despues de LifeTime segundos
    }
    
    function ClearSquad_A() {
    	ClearTimer(EnemyType_A);
    }
    
    /** SQUAD B */ 
    function SetSquad_B(name EnemyType, name AttackType, float Periodo, float Lifetime)  {
    		EnemyType_B = GetSpawnFunctionName(EnemyType, "B");
    		AttackType_B = AttackType;
    		SetTimer(Periodo, true, EnemyType_B); // espawneado de enemigos cada Periodo segundos
    		SetTimer(LifeTime, false, 'ClearSquad_B'); // eliminación de timer anterior despues de LifeTime segundos
    }
    function ClearSquad_B() {
    	ClearTimer(EnemyType_B);
    }
    
    
    function name GetSpawnFunctionName(name EnemyType, String squad) {
    	if(squad == "A") {
    		if(EnemyType == 'Egg') EnemyType = 'SpawnEgg_A';
    		else if(EnemyType == 'Egg2') EnemyType = 'SpawnEgg2_A';
    		else if(EnemyType == 'Cangrejo') EnemyType = 'SpawnCangrejo_A';
    		else if(EnemyType == 'Anguilla') EnemyType = 'SpawnAnguilla_A';		
    	}
    	else if (squad == "B")  {
    		if(EnemyType == 'Egg') EnemyType = 'SpawnEgg_B';
    		else if(EnemyType == 'Egg2') EnemyType = 'SpawnEgg2_B';
    		else if(EnemyType == 'Cangrejo') EnemyType = 'SpawnCangrejo_B';
    		else if(EnemyType == 'Anguilla') EnemyType = 'SpawnAnguilla_B';		
    	}
    	return EnemyType;
    }
    
    
    /** SPAWNING BICHOS AQUI , cada tipo tiene una versión según el numero de squads que hayan (por el momento dos A y B) **/
    function SpawnEgg_A() {
    	local SamEnemyEgg newPawn;
    	NewPawn = Spawn(class'SamEnemyEgg',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_A); // 
    }
    function SpawnEgg2_A() {
    	local SamEnemyEgg2 newPawn;
    	NewPawn = Spawn(class'SamEnemyEgg2',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_A); // 
    }
    function SpawnCangrejo_A() {
    	local SamEnemyCangrejo newPawn;
    	NewPawn = Spawn(class'SamEnemyCangrejo',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_A); // 
    }
    function SpawnAnguilla_A() {
    	local SamEnemyAnguilla newPawn;
    	NewPawn = Spawn(class'SamEnemyAnguilla',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_A); // 
    }
    
    /** SQUAD B*/
    function SpawnEgg_B() {
    	local SamEnemyEgg newPawn;
    	NewEggPawn = Spawn(class'SamEnemyEgg',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_B); // 
    }
    function SpawnEgg2_B() {
    	local SamEnemyEgg2 newPawn;
    	NewPawn = Spawn(class'SamEnemyEgg2',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_B); // 
    }
    function SpawnCangrejo_B() {
    	local SamEnemyCangrejo newPawn;
    	NewPawn = Spawn(class'SamEnemyCangrejo',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_B); // 
    }
    function SpawnAnguilla_B() {
    	local SamEnemyAnguilla newPawn;
    	NewPawn = Spawn(class'SamEnemyAnguilla',,,vect(0, -1000, 0)); // el vector es un punto lejos de la zona visible en el juego
    	SamEnemyController(NewPawn.Controller).Initial(AttackType_B); // 
    }
    Last edited by radomiro; 03-04-2011 at 09:42 PM.
    do you want to learn UDK and you are a newbie?
    - first learn some basics about level edition
    - then do make Hourences Basic Game Tut. to work (dont go further till you make it work)
    - and only then learn the Mougli's lessons
    - official UDK info

  9. #9
    Palace Guard

    Join Date
    Jul 2006
    Location
    WorldInfo_61
    Posts
    3,170

    Default

    I didnt actually suggest that at all, I was talking about in certain languages you can do:

    Code:
    func myfunc();
    func myfunc(float y);
    func myfunc(int i);
    For that code Id be using a switch within a timer, set squads to some kind of array or even a struct array. You could get that down to less then 25 lines easy.
    Last edited by MonsOlympus; 03-04-2011 at 09:55 PM.

  10. #10
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,828

    Default

    That is way, way more complex than it needs to be, I think.
    Trendy Entertainment
    http://www.trendyent.com/ http://www.dungeondefenders.com/
    - Please don't send me private messages asking programming questions, those would be better asked on the Programming forum here. Thanks
    - Thoughts and opinions expressed by me are not meant to express the thoughts and opinions of Trendy Entertainment or anyone else related to Trendy.


 
Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved. vBulletin skin by CompletevB.com.