Jump to content

Recommended Posts

Hello everyone,

first time poster, but long time fan of the game. Recently i started working on a charactermod, and slowly i'm getting to a point where it's more or less playable. So i asked a friend to hop onto a server with me to test the character. It's Alice Liddell from Alice in Wonderland. 

The problem: The character comes with items that change her size. A cake that makes her grow, and a potion that makes her shrink. Now when i use the potion on my character to shrink, which uses the inst.transform.setscale(x,y,z), i also apply a movementspeedbuff to my inst.components.locomotor.runspeed, to offset the loss of movementspeed that comes with scaling down my character. 
After shrinking myself down, i'm at the correct speed which i expected to have, while my friend is running around twice as fast. The modifier to the runspeed variable is quite large when shrinking, so i assume that is where they got the speedboost from. 


Since i don't know anything about LUA, i wanted to ask if someone who is more experienced knows what i've missed when setting up the character. I assume it's something i'm unaware of concerning LUA, but if needed i can link to the workshop page where the WIP version of the mod is uploaded.

 

Many thanks for the help!

Alice.zip

Edited by bruweiz

I don't understand what the problem is. Can you describe specifically what isn't working as you want it to? Something about your speed modifier working fine, but your friend suddenly moves at double speed without using any of the items?

Edited by Ultroman

Well yeah. I hosted a server for me and my friend to connect to. We both played the modded character. I spawned a couple cakes and potions for us to test them. The sizechange worked as expected. I ate a cake, my character grew twice as big. I drank potions, and i shrank to half the size. When growing the playermodel using inst.transform.setscale, your speed also increases accordingly, so to counteract that, i apply a movementspeed modifier at inst.components.locomotor.runspeed that reduces my speed drastically. For shrinking it's the same. Scaling the model down makes me slower, so i apply a movementspeed modifier that increases my speed drastically. Now after i drink the potion, i ended up smaller, but at around the same speed as before, since i got both the effects of scaling my size down reducing my speed, and the modifier applied to my locomotor component increasing my speed to counteract that. 
And all of a sudden, my friend was running around at almost twice the speed they were supposed to. It seems like me drinking a potion on my character didn't apply the change in size to them, but it did apply the effects of the change in my inst.components.locomotor.runspeed to them.  The reverse was also true. Me eating the cakes increased my characters size, but both me and my friends character were applied a movementspeed decrease, even though it should have been only my character.

I hope this clears it up. 

Looking at your code, it should only apply to the correct character. I don't see how it could affect you both. I think you're being fooled by not handling the state of the variables properly. My best advice, is to throw in a slew of print-statements, very structured, perhaps with a "------------START--------------" as the first thing in your oneat function and then print all the variables you're using (the current state), then make your changes, and then print the entire state again, then a "------------END--------------". Make sure to also print which size/scale you're expecting to be going from and going to. Everything you can think of that might get you a sliver of information about what is going wrong, print it. If you don't find anything immediately, go to your sanityhunger function and do the same, only fewer prints, and probably another splitter e.g. ".............START.............", since it's going to be printing every 0.2 seconds. See if you can pick up a discrepancy between what you expect to happen and then test it out to see what actually happens. It's called "testing a use-case". Make a scenario. In this case you have a sequence you know to be faulty, so you already have a use-case you need to debug, and you know which results you expect. When you've fixed that use-case, try to think of another way it could screw up, perhaps the reverse order of drinking/eating.

There's information about how to use print-statements and a few tips on debugging in the newcomer post, as well.

Edited by Ultroman
  • Thanks 1

I found where i messed up. I declared the variables where i store the stat modifiers for the change in size in local VarName, and not in inst.VarName. Playing with more than one instance of the character on the server lead to each instance of the character on the server to read and write into the same variables. This made the speedboost of one player apply to all players that were playing the character.

Thanks again for the help.

  • Like 1

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
×
  • Create New...