Forum

> > CS2D > Scripts > [Solved]Bigger, lower, equal etc. are buggy.
Forums overviewCS2D overview Scripts overviewLog in to reply

English [Solved]Bigger, lower, equal etc. are buggy.

20 replies
Page
To the start Previous 1 2 Next To the start

old [Solved]Bigger, lower, equal etc. are buggy.

Mora
User Off Offline

Quote
Hello us
I got one problem when run this lua:
The code >


The error is:
For example i have 15000$ and press F2(which is call the menu via function) and get this:


The problem is with
<=, >=, =, ==, <, >
.

Maybe i am using them not properly or not even correct at all? Or even something else causes the problem?

Sorry for my english
Thank you very much.
edited 1×, last 13.07.16 07:11:03 pm

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Masea
Super User Off Offline

Quote
Spoiler >

Try this.

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Mora
User Off Offline

Quote
user Masea has written
Spoiler >

Try this.

Yeah it is works!
Thank you very much,
have a nice day.


Another question:
I used alot of "local booleans", nothing wrong with their usage?

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Mora
User Off Offline

Quote
user Masea has written
@user Mora: If you're going to use them only at that function, then eveything is fine. Otherwise, setup them out of the function and delete the existing ones.

Exactly them - yes.
I have some menus which have suchs booleans. For example the house menu. There are another ones, such as:
doorcheck

allowbuilding

door bell

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Rainoth
Moderator Off Offline

Quote
I find it a bit impractical. Wouldn't you prefer less copy pasting in these cases?

I wrote this in a few minutes so I wouldn't be surprised if I missed out something. Just trying to show that you don't need to make tons of variables and copy paste a lot to achieve the same result. Tables simplify everything after all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function moneymenu (id)
	local a = {
	[50000] = "Drop 50000$|50K$",
	[25000] = "Drop 25000$|25K$",
	[10000] = "Drop 10000$|10K$",
	[5000] = "Drop 5000$|5K$",
	[1000] = "Drop 1000$|1K$",
	[500] = "Drop 500$|0.5K$",
	[100] = "Drop 100$|0.1K$"
	}

	local menuString = "Local menu,"
	for k,v in pairs (a) do
		if players[id].money < k then
			a[k] = "("..v..")"
			if k ~= 100 then
				menuString = menuString..a[k]..","
			else
				menuString = menuString..a[k]
			end
		end
	end
	menu(id,menuString)
end

P.S. I may be wrong but ">" is usually reffered to as "greater" rather than "bigger" ^.o

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Mora
User Off Offline

Quote
@user Rainoth: By copying/pasting you mean that i have to add such things in more than one function?-If yes, there the answer is:
They used once in the menu which you see ^.
But if you explain it as second part after your question:
I'm not really good at lua. But i don't understand how to use this:
The code >

Where i can find explanation of that, instead of just copy/paste your code?
/sorry for my english.. all the time :<

Admin/mod comment

Removed unnecessary quote. /user GeoB99

old Re: [Solved]Bigger, lower, equal etc. are buggy.

DC
Admin Off Offline

Quote
Regarding local variables in Lua in general: It's good practice to use them and they are fast. It's recommended to use local variables instead of global variables whenever you can / it makes sense.

https://www.lua.org/pil/4.2.html has written
It is good programming style to use local variables whenever possible. Local variables help you avoid cluttering the global environment with unnecessary names. Moreover, the access to local variables is faster than to global ones.

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Dousea
User Off Offline

Quote
Here you go. Rather than creating a new table for
a
every time
moneymenu
function called (and requires a new spot of memory), let's save it in the body. Keep in mind that it only uses 3 local variables.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local a = {50000, 25000, 10000, 5000, 1000, 500, 100}

function moneymenu(id)
	local contents = "Local menu,"
	local button
	
	for _, value in ipairs(a) do
		button = "Drop " .. value .. "$|" .. (value / 1000) .. "K$)"
		contents = contents .. (players[id].money < value and "(" .. button .. ")" or button) .. ","
	end
	
	if (players[id].license == 0) then
		button = players[id].money < 175000 and "(Not enough money|175$K)" or "Buy license-175000$|175K$")
	elseif (players[id].license == 1) then
		button = "(License bought|F3 to use.)"
	end
	
	contents = contents .. button .. ","
	
	if (players[id].house == 0) then
		button = "(No house yet)"
	elseif (players[id].house < 0) then
		button = "Control the home|St:0,N:0"
	end
	
	contents = contents .. button
	
	menu(id, contents)
end

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Mora
User Off Offline

Quote
@user DC: global? m, what you mean? I never heard of that, or maybe i don't understand what u r mean exactly. Can i have one example?

Only the function i show you in the Post includes these booleans.
@user Dousea: that's pretty hard for me, i would not like to simply copy/paste the code. @user Rainoth: already helped me with them.

old Re: [Solved]Bigger, lower, equal etc. are buggy.

Mora
User Off Offline

Quote
I don't know how does work the save system, but i just copied and pasted it and a guy which gave me that said where i have to change the lines to kept the values saved. It was along ago so i get no explanation of that. Also to teach it from you guys is much easiest, for sure you have time or(and) want to explain.
Still i don't know some lua lines which i just learnt as a "text", i just paste it from my brain to the .lua file and it works. For example array function. That's all.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview