Jump to content

Crash when talking


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Developer
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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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
 Share

×
  • Create New...