Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

Using Dynamic Code in C# with Events? -


i'm implementing script engine in game wrote using c# "dynamic" feature.

how system should work when script called, should register events listens for, return control application. when event script listening fired script should execute. 1 thing i'd implement in script engine have methods names automatically bind events. example, onturnstart() listener should automatically bind turnstart event.

the scripts need execute existing methods , change variable values in classes; stuff player.takedamage() , player.hp = somevalue. scripts need wait start of players' turn , end of players' turn before being unloaded.

the complicated part these scripts need able changed without making code changes game. (security aside) current plan have script changes automatically download when game starts ensure players using same version of scripts.

however have 3 questions:
1) how register , unregister script event listeners?
2) can dynamic code listen events?
3) (how) can register events dynamically?

this first time using c#'s dynamic feature, appreciated.

thanks
--michael

i'm not sure you've got right end of stick dynamic keyword. doesn't let interpret new code @ runtime. let bypass static type checking delaying resolution of operations until runtime.

if you're looking "script" game, want take @ integrating lua, ironpython, or 1 of other dlr languages:-

otherwise, usual thing have along lines of:-

interface ibehavior {   // binds whatever events behaviour needs, , optionally adds   // collection of behaviours on entity.   void register(entity entity); }  // example public abstract class turnendingdosomethingbehavior {   public void register(entity entity)   {     entity.turnending += (s, e) => dosomething();   }    private abstract void dosomething(); } 

the question is, want able add entirely new behaviours after compile-time? if you'll need expose or of game-state scripting language.

or sufficient able compose existing behaviours @ runtime?


after edit

i'm still unsure, honest, requirement dynamic keyword , dlr. game's launcher can download class library full of behaviours can pull down set of scripts! (that's minecraft's launcher if memory serves)

if absolutely must use dlr take @ links posted. you'll have expose of game state necessary 1 of dlr languages. events exposed first-order-function properties. shouldn't need "dynamic" keyword basic stuff.

quick example in ironpython:-

def dosomethingwhendamagetaken(*args):   #do whatever...  player.damagetaken += dosomethingwhendamagetaken 

the player class:-

public class player {   public event eventhandler damagetaken;    // ... } 

you set like:-

scriptengine engine = python.createengine(); scriptruntime runtime = engine.runtime; scriptscope scope = runtime.createscope();  // in actual application might // parsing script user input. scriptsource source = engine.createscriptsourcefromfile(...);   player p = new player(); scope.setvariable("player", p); source.execute(scope); 

some links started:-


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -