Is there a better way of writing something like
[CODE]
if (mousex >= (lastdrawX + 500) and (mousex <= (lastdrawX - 500)) and (mousey >= (lastdrawY + 500) and (mousey <= (lastdrawY - 500)))) then return end
[/CODE]
Not that the example above works, and not that the amount would be 500 (what I mean is, check if the new cursor position is plus or minus a certain number from either side of the previous cursor position, and if so, end it)
[code]
if mousex - 500 <= lastdrawx <= mousex + 500 and mousey - 500 <= lastdrawy <= mousey + 500 then
end
[/code]
This is the inverse, if the number is between then it will continue, you can not() the whole statement and do your return end
Sorry, I meant if it ISN'T between then continue :P
Surely there's a faster way to write
[CODE]
if ((mousex <= (lastdrawX + 500)) and (mousex >= (lastdrawX - 500)) and ((mousey <= (lastdrawY + 500)) and (mousey >= (lastdrawY - 500)))) then return end
[/CODE]
That will get called A LOT, so I need an alternative if possible...
[code]
if mousex - 500 <= lastdrawx <= mousex + 500 and mousey - 500 <= lastdrawy <= mousey + 500 then return end
[/code]
If the number is between, then it won't continue.
[QUOTE=AnonTakesOver;47455257][code]
if mousex - 500 <= lastdrawx <= mousex + 500 and mousey - 500 <= lastdrawy <= mousey + 500 then return end
[/code]
[/QUOTE]
Attempt to compare boolean with number? Where's the bool? (I think yours needs brackets)
[editline]4th April 2015[/editline]
Just separated them, the problem is this line:
[CODE]
<= mousex + 500
[/CODE]
[QUOTE=MPan1;47458410]Attempt to compare boolean with number? Where's the bool? (I think yours needs brackets)
[editline]4th April 2015[/editline]
Just separated them, the problem is this line:
[CODE]
<= mousex + 500
[/CODE][/QUOTE]
[lua]if mousex - 500 <= lastdrawx and lastdrawx <= mousex + 500 and mousey - 500 <= lastdrawy and lastdrawy <= mousey + 500 then return end[/lua]
[editline]4th April 2015[/editline]
Each logical opperation is carried out in order. When you do this:
[lua] mousex - 500 <= lastdrawx <= mousex + 500 [/lua]
Lua does
[lua] ( mousex - 500 <= lastdrawx ) <= mousex + 500 [/lua]
Still has an error though...
[editline]4th April 2015[/editline]
Wait, no it doesn't...
Did you try adding brackets?
It doesn't have an error. By the way, I'm trying to think of a better way to create IMaterials automatically. Currently to create them, I use this function:
[CODE]
local function creatematerial(matpath)
new_material = CreateMaterial("MSPaintMaterialCustom/" .. matpath,"UnlitGeneric",
{
["$basetexture"] = matpath,
["$vertexcolor"] = 1,
["$vertexalpha"] = 1,
} )
end
[/CODE]
But, this only gets called EVERY FRAME whenever you try to draw anything... I'd rather have it done automatically. So far, I use a DIconLayout to create all the possible brushes (which need a custom material, made by creatematerial), which looks like this
[CODE]
local materialtable = {
"gui/center_gradient",
"sprites/sent_ball"
} //I'll add more
for k, v in pairs( materialtable ) do
local BrushItem = HomeOptionBrush:Add( "DImageButton" )
BrushItem:SetSize( 40, 40 )
BrushItem:SetImage( v )
BrushItem.DoClick = function()
old_material = v
end
end
[/CODE]
'Old_material' is the material path, which is then used by
[CODE]
table.insert( drawtable, { drawtype = "default", x = mousex, y = mousey, size = HomeOptionSize:GetValue(), rotation = 0, color = tablecolorvar, material = old_material } )
[/CODE]
And then, this value is actually turned into an IMaterial by
[CODE]
creatematerial( v.material )
surface.SetMaterial( new_material )
[/CODE]
v.material being what the variable old_material was at that stage. I'd rather do something like
[CODE]
for k, v in pairs( materialtable ) do
local BrushItem = HomeOptionBrush:Add( "DImageButton" )
BrushItem:SetSize( 40, 40 )
BrushItem:SetImage( v )
creatematerial(v)
BrushItem.DoClick = function()
//Not sure
end
end
[/CODE]
But then how would I obtain and use the IMaterial's name?
The reason I'm cycling through every single material of every single shape just to create it is so you would be able to save and load drawings, although I could just do that when something actually gets loaded. I'll probably think of something.
[editline]4th April 2015[/editline]
Actually, I could probably just get the material path from the previous brush and just add a bit before it.
Oh. Obvious problem with what I wanted to do. I wanted to automatically create the IMaterials when the DIconLayout buttons load, but here's the problem.
[CODE]
local oldmaterial = nil
for k, v in pairs( materialtable ) do
local BrushItem = HomeOptionBrush:Add( "DImageButton" )
BrushItem:SetSize( 40, 40 )
BrushItem:SetImage( v )
creatematerial(v) //This should autocreate the materials
BrushItem.DoClick = function()
old_material = v //old_material is the value parts added to the table of all parts to draw get their material path from
end
end
//A bit later, in the painting code
surface.SetMaterial( "mspaintmaterialcustom/" .. v.material )
surface.DrawTexturedRectRotated( v.x, v.y, v.size, v.size, v.rotation )
//v.material is part of the table, the material value
//This is the material creation part
local function creatematerial(matpath)
new_material = CreateMaterial("mspaintmaterialcustom/" .. matpath,"UnlitGeneric",
{
["$basetexture"] = matpath,
["$vertexcolor"] = 1,
["$vertexalpha"] = 1,
} )
end
[/CODE]
The problem with what I want to do above, is that surface.SetMaterial won't work, as I'm trying to use an existing IMaterial incorrectly. What I want to do is return the IMaterial value from the creatematerial function (but not with a variable, as more than one will be in use), so it can later be easily accessed (by knowing the material path of the original material). How would I do this? With tables or something?
[editline]5th April 2015[/editline]
I could easily get the new_material value from right after the function gets called, but then how would you make the button switch to it?
[editline]5th April 2015[/editline]
If there was something like IMaterial:GetByString() that'd work...
I thought about using variables and naming them the material path, and then loading these variables later (as their IMaterials), but then how would I make the variables local to the script? I'd need to use some sort of wildcard as I'd need to modify these variables (and create more) in the IMaterial-creating function...
I still need help...
[QUOTE=MPan1;47447965]What is render() meant to call? Is it just my function? If so, why is there a blank space in between os.clock()>next? Is this just meant to make the computer calculate nothing then actually do something?[/QUOTE]
it is an empty loop, basically a delay to slow down the rendering. Yes render is your function.
I don't need help with that, I need an alternative to the fairly annoying thing I'm trying to do about auto-loading materials. All I need is some way for me to know what the name of the material var (or just the IMaterial is) to call it whenever it is needed.
[editline]12th April 2015[/editline]
It may make more sense if you read the horrendously long thing I wrote before.
Sorry, you need to Log In to post a reply to this thread.