Sign in to follow this  
Makishim

Crash when talking

Recommended Posts

Makishim    1

inst.components.talker:Say(inst.level)

 

My server's crashing when my char try to talk. But only when my server have caves; when they're disabled I don't have any trouble.

Share this post


Link to post
Share on other sites
Ultroman    193

That's probably because the character only has the level-variable on the server and not on the clients. If you just declare the variable above your ismastersim check, the error will go away, but on the clients it'll always show you saying the initial value, even after you have changed the value on the server. What you're looking at, is a problem that requires you to sync a networked variable between the client and server, so both have an up-to-date level-variable at all times.

I'm not entirely sure how to do that, as I have never done that before. I'm sure you can find a thread on this forum, if you search for keywords like: sync network variable

  • Like 1

Share this post


Link to post
Share on other sites
YakumoYukari    76

Talker:Say() method's script argument must be a string otherwise, crash.
So If inst.level is nil or number value, will cause the crash.
 

Share this post


Link to post
Share on other sites
Ultroman    193
1 hour ago, YakumoYukari said:

Talker:Say() method's script argument must be a string otherwise, crash.
So If inst.level is nil or number value, will cause the crash.
 

I'm pretty sure LUA has automatic tostring() for numbers, so that won't cause a crash.

Otherwise this wouldn't work

print("foo"..inst.components.health.current)

but it does. Unless I'm missing something, in which case please enlighten me :)

Also, it works without caves.

Edited by Ultroman

Share this post


Link to post
Share on other sites
bizziboi    999
4 hours ago, Ultroman said:

Unless I'm missing something, in which case please enlighten me

It only does that if it can deduce it needs to be converted to string (or coerced as it's called in the lingo).

Since your example allows Lua to deduce it has to be a string (because the number is concatenated to string, so it reasons it must be converted to string). However, the following code will crash, it surpasses Lua's level of type coercion.

function test(s)
	print(s:sub(1,1))
end

test(3)

The more you know :)

(well, okay, it would be very hard for Lua to know this is expected to be a string, but just to show that string coercion doesn't always work)

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
Ultroman    193
14 hours ago, bizziboi said:

It only does that if it can deduce it needs to be converted to string (or coerced as it's called in the lingo).

The more you know :)

2

Indeed! Thanks for the correction.

Share this post


Link to post
Share on other sites
Makishim    1
21 hours ago, YakumoYukari said:

Talker:Say() method's script argument must be a string otherwise, crash.
So If inst.level is nil or number value, will cause the crash.
 

But my Talker:Say() is fine when is a normal server. He just crash when caves are enabled.

Share this post


Link to post
Share on other sites
Ultroman    193

Maybe the Say function does some work for you, in regards to coercing the variable to be a string. I don't know.

Your problem is definitely that your server-instance has the level-variable, and the client-instance does not. Look into netvars or syncing variables between server and client.

Edited by Ultroman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this