efun simulate help

45 views
Skip to first unread message

seik...@gmail.com

unread,
Apr 8, 2021, 10:57:38 PM4/8/21
to LDMud Talk
undefinedp - determine whether or not a given value is undefined.
 
int undefinedp( mixed arg );
 
Return 1 if `arg' is undefined.  'arg' will be undefined in the following
cases:
 
<DL>
* it is a variable set equal to the return value of a call_other to a
non-existent method (e.g. arg = call_other(obj, "???")).
* it is a variable set equal to the return value of an access of an
element in a mapping that doesn't exist (e.g. arg = map[not_there]).
* it has not yet been initialized.
* it points to a destructed object.
* it is a function (formal) parameter that corresponds to a missing actual argument.
</DL>
I am trying to convert a mudos's mudlib to ldmud
the mudlib use efun undefined a lot how can I simulate it in ldmud 
can anybody help me please thanks very much

seik...@gmail.com

unread,
Apr 9, 2021, 2:36:38 AM4/9/21
to LDMud Talk
when the arg is an element in mapping undefinedp(map[not_here]) returns 1
I can use member(map,not_here),  but there are too many undefinedp(map[not_here]) 
replace them to member(map,not_here) by hand is impossible. so I need a simulate efun

Michael Conley

unread,
Apr 9, 2021, 7:25:14 AM4/9/21
to Discussion of the LDMud driver.
Good to hear you are making the jump to LDMud.

Could you share a MudOS code sample of where you are coming from?  Perhaps that will help understand the use case here.  Also, join up to the new Discord group for LPC.  There is an LDMud channel. Detail here: https://www.reddit.com/r/MUD/comments/mdbbaa/new_discord_server_for_lpc_conversation/.



--
You received this message because you are subscribed to the Google Groups "LDMud Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ldmud-talk+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ldmud-talk/fad01f59-7dd2-4000-bdb3-944079239f07n%40googlegroups.com.

Invisible

unread,
Apr 9, 2021, 7:50:40 AM4/9/21
to ldmud...@googlegroups.com

Hi there,

The main problem will be that there is no 'undef' value in LDmud, all variables are implicitly initialized to 0. So a simul_efun that does all you want depending on context is (as far as I know) impossible to implement. Both map[not_there] and map[value_0] return the same "0" (that's why there is a member() function in the first place). So even if you implement a sefun::undefinedp(arg) you will not be able to tell the difference from arg alone.

In some cases like e.g. a destructed object you could have some luck checking the type, but then again a (object)0 for a destructed object is exactly the same as if there never was an object to begin with.

regards
  Invis

--

seik...@gmail.com

unread,
Apr 9, 2021, 8:45:59 PM4/9/21
to LDMud Talk

my = ob->query_entire_dbase();
 
ob->set("default_actions", (: call_other, __FILE__, "query_action" :));
 
if( undefinedp(my["age"]) ) my["age"] = 14;
if (undefinedp(my["str"])) my["str"] = 10 + random(21);
if (undefinedp(my["con"])) my["con"] = 10 + random(21);
if (undefinedp(my["dex"])) my["dex"] = 10 + random(21);
if (undefinedp(my["int"])) my["int"] = 80 - my["str"] - my["con"] - my["dex"];
if (undefinedp(my["per"])) my["per"] = 10 + random(21);
if (undefinedp(my["kar"])) my["kar"] = 10 + random(21);
if (undefinedp(my["sta"]) || my["sta"]==0) my["sta"] = 10 + random(21);
if (undefinedp(my["cps"]) || my["cps"]==0) my["cps"] = 10 + random(21);
if (undefinedp(my["cor"]) || my["cor"]==0) my["cor"] = 10 + random(21);
 this code is used to initialize same properties
I can replace the undefinedp by member but there are too many replace it
hand by hand is impossible

seik...@gmail.com

unread,
Apr 9, 2021, 8:51:16 PM4/9/21
to LDMud Talk

protected nomask  mixed _query( mapping map, string *parts )
{
mixed value;
int i, s;
 
value = map;
s = sizeof( parts );
for( i = 0 ; i < s ; i++ ) {
if( undefinedp( value = value[parts[i]] ) )
break;
if( !mappingp( value ) )
break;
}
return value;
}
and code like this 
在2021年4月9日星期五 UTC+8 下午7:25:14<Tamarindo> 写道:

Invisible

unread,
Apr 9, 2021, 8:53:51 PM4/9/21
to ldmud...@googlegroups.com

Hello again,

At least in this example it looks as if you can just replace undefinedp() with a check for 0.

cu

  Invis

seik...@gmail.com

unread,
Apr 9, 2021, 9:56:15 PM4/9/21
to LDMud Talk
yes you are right

Zesstra

unread,
Apr 10, 2021, 5:30:24 AM4/10/21
to ldmud...@googlegroups.com
On 09.04.21 04:57, seik...@gmail.com wrote:
> undefinedp - determine whether or not a given value is undefined.
> int undefinedp( mixed arg );
> Return 1 if `arg' is undefined.  'arg' will be undefined in the following
> cases:

Invisible already mentioned it - I agree and put it slightly different words:

Technically there is no undefined value in LDMud exposed to the LPC side.
All entities are initialized to a defined value. What people mostly mean by
undefined is "the wizard did not explicitly assign a value (yet)".

However, in many cases that also translates to something like "is the value a
valid one for my purposes".

Therefore in some cases:
If you know the *type* of a variable, you can check whether it contains a
non-zero value of that type, e.g. if the value in a mapping variable is an
actual mapping and not 0.
But this is limited to cases, where the type is known - you don't know it for
the values in mappings, you need member in that case or check for !=0 if 0 is
not a valid value.

tl&dr; In general you need to know something about the context to know whether
a value is "valid" or not and to decide if it counts as "undefined" for you.

In the long run, you will program in a way that takes this into account. ;-)

Bye,
Zesstra
--
MorgenGrauen -
1 Welt, mehr als 200 Programmierer , mehr als 16000 Raeume,
viel mehr als 7000 unterschiedliche Figuren, 90 Quests, 13 Gilden,
ueber 5000 Waffen und Ruestungen, keine Umlaute und ein Haufen Verrueckter.
Existenz: mehr als 25 Jahre
http://mg.mud.de/

Stephan Weinberger

unread,
Apr 10, 2021, 6:39:49 AM4/10/21
to ldmud...@googlegroups.com
Though - and I think we talked about this in the past - having a 'none'
or 'undef' value might actually be quite useful sometimes. E.g. when
interacting with databases that have 'NULL' columns.

But I understand that this would likely require major changes to the driver.


cya,
  Invis

seik...@gmail.com

unread,
Apr 10, 2021, 10:42:35 AM4/10/21
to LDMud Talk
I made a sefun like this
int undefinedp(mixed what) 
{
if (what==0) return 1;
return 0;
}
it works

Karl Tiedt

unread,
Apr 10, 2021, 3:34:35 PM4/10/21
to Ldmud Talk
That sefun works great until your defined value is actually a zero... 

-Karl Tiedt


--
You received this message because you are subscribed to the Google Groups "LDMud Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ldmud-talk+...@googlegroups.com.

seik...@gmail.com

unread,
Apr 10, 2021, 9:01:09 PM4/10/21
to LDMud Talk

 in that case I have to use member
I can make do with this just for some time

seik...@gmail.com

unread,
Apr 10, 2021, 9:22:04 PM4/10/21
to LDMud Talk

there is no undefined type such as nill/null  I can not tell an undefined 0 from a literal integer 0
Reply all
Reply to author
Forward
0 new messages